Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: crypto/sha1_perftest.cc

Issue 2081553003: crypto: Add peformance test for SHA1 to compare against base Base URL: https://chromium.googlesource.com/chromium/src.git@cryto-sha1
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « crypto/crypto.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5
6 #include "crypto/sha1.h"
7
8 #include <stddef.h>
9
10 #include <string>
11
12 #include "base/sha1.h"
13 #include "base/time/time.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/perf/perf_test.h"
16
17 namespace {
18
19 static const int kBenchmarkRuns = 2000000;
20
21 } // namespace
22
23 TEST(SHA1PerfTest, SingleBlock) {
24 const std::string kStartingString = "abc";
25 std::string output;
26 std::string input;
27 base::TimeTicks start;
28
29 input = kStartingString;
30 start = base::TimeTicks::Now();
31 for (int i = 0; i < kBenchmarkRuns; ++i) {
32 output = base::SHA1HashString(input);
33 input = output;
34 }
35 double base_hashes_per_second =
36 kBenchmarkRuns / (base::TimeTicks::Now() - start).InSecondsF();
37 std::string base_output = output;
38
39 input = kStartingString;
40 start = base::TimeTicks::Now();
41 for (int i = 0; i < kBenchmarkRuns; ++i) {
42 output = crypto::SHA1HashString(input);
43 input = output;
44 }
45 double crypto_hashes_per_second =
46 kBenchmarkRuns / (base::TimeTicks::Now() - start).InSecondsF();
47 std::string crypto_output = output;
48
49 EXPECT_EQ(crypto_output, base_output);
50
51 perf_test::PrintResult("sha1_perf", "single", "base", base_hashes_per_second,
52 "hashes/s", true);
53 perf_test::PrintResult("sha1_perf", "single", "crypto",
54 crypto_hashes_per_second, "hashes/s", true);
55 perf_test::PrintResult("sha1_perf", "single", "improvement",
56 crypto_hashes_per_second / base_hashes_per_second,
57 "times", true);
58 }
59
60 TEST(SHA1PerfTest, MultiBlock) {
61 const std::string kStartingString =
62 "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc";
63 std::string output;
64 std::string input;
65 base::TimeTicks start;
66
67 input = kStartingString;
68 start = base::TimeTicks::Now();
69 for (int i = 0; i < kBenchmarkRuns; ++i) {
70 output = base::SHA1HashString(input);
71 input = output;
72 input.append(output);
73 input.append(output);
74 }
75 double base_hashes_per_second =
76 kBenchmarkRuns / (base::TimeTicks::Now() - start).InSecondsF();
77 std::string base_output = output;
78
79 input = kStartingString;
80 start = base::TimeTicks::Now();
81 for (int i = 0; i < kBenchmarkRuns; ++i) {
82 output = crypto::SHA1HashString(input);
83 input = output;
84 input.append(output);
85 input.append(output);
86 }
87 double crypto_hashes_per_second =
88 kBenchmarkRuns / (base::TimeTicks::Now() - start).InSecondsF();
89 std::string crypto_output = output;
90
91 EXPECT_EQ(crypto_output, base_output);
92
93 perf_test::PrintResult("sha1_perf", "multi", "base", base_hashes_per_second,
94 "hashes/s", true);
95 perf_test::PrintResult("sha1_perf", "multi", "crypto",
96 crypto_hashes_per_second, "hashes/s", true);
97 perf_test::PrintResult("sha1_perf", "multi", "improvement",
98 crypto_hashes_per_second / base_hashes_per_second,
99 "times", true);
100 }
OLDNEW
« no previous file with comments | « crypto/crypto.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698