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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crypto/crypto.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/sha1_perftest.cc
diff --git a/crypto/sha1_perftest.cc b/crypto/sha1_perftest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7ab0a0c2673a012037d5cdbd872564aba93550fb
--- /dev/null
+++ b/crypto/sha1_perftest.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+#include "crypto/sha1.h"
+
+#include <stddef.h>
+
+#include <string>
+
+#include "base/sha1.h"
+#include "base/time/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/perf/perf_test.h"
+
+namespace {
+
+static const int kBenchmarkRuns = 2000000;
+
+} // namespace
+
+TEST(SHA1PerfTest, SingleBlock) {
+ const std::string kStartingString = "abc";
+ std::string output;
+ std::string input;
+ base::TimeTicks start;
+
+ input = kStartingString;
+ start = base::TimeTicks::Now();
+ for (int i = 0; i < kBenchmarkRuns; ++i) {
+ output = base::SHA1HashString(input);
+ input = output;
+ }
+ double base_hashes_per_second =
+ kBenchmarkRuns / (base::TimeTicks::Now() - start).InSecondsF();
+ std::string base_output = output;
+
+ input = kStartingString;
+ start = base::TimeTicks::Now();
+ for (int i = 0; i < kBenchmarkRuns; ++i) {
+ output = crypto::SHA1HashString(input);
+ input = output;
+ }
+ double crypto_hashes_per_second =
+ kBenchmarkRuns / (base::TimeTicks::Now() - start).InSecondsF();
+ std::string crypto_output = output;
+
+ EXPECT_EQ(crypto_output, base_output);
+
+ perf_test::PrintResult("sha1_perf", "single", "base", base_hashes_per_second,
+ "hashes/s", true);
+ perf_test::PrintResult("sha1_perf", "single", "crypto",
+ crypto_hashes_per_second, "hashes/s", true);
+ perf_test::PrintResult("sha1_perf", "single", "improvement",
+ crypto_hashes_per_second / base_hashes_per_second,
+ "times", true);
+}
+
+TEST(SHA1PerfTest, MultiBlock) {
+ const std::string kStartingString =
+ "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc";
+ std::string output;
+ std::string input;
+ base::TimeTicks start;
+
+ input = kStartingString;
+ start = base::TimeTicks::Now();
+ for (int i = 0; i < kBenchmarkRuns; ++i) {
+ output = base::SHA1HashString(input);
+ input = output;
+ input.append(output);
+ input.append(output);
+ }
+ double base_hashes_per_second =
+ kBenchmarkRuns / (base::TimeTicks::Now() - start).InSecondsF();
+ std::string base_output = output;
+
+ input = kStartingString;
+ start = base::TimeTicks::Now();
+ for (int i = 0; i < kBenchmarkRuns; ++i) {
+ output = crypto::SHA1HashString(input);
+ input = output;
+ input.append(output);
+ input.append(output);
+ }
+ double crypto_hashes_per_second =
+ kBenchmarkRuns / (base::TimeTicks::Now() - start).InSecondsF();
+ std::string crypto_output = output;
+
+ EXPECT_EQ(crypto_output, base_output);
+
+ perf_test::PrintResult("sha1_perf", "multi", "base", base_hashes_per_second,
+ "hashes/s", true);
+ perf_test::PrintResult("sha1_perf", "multi", "crypto",
+ crypto_hashes_per_second, "hashes/s", true);
+ perf_test::PrintResult("sha1_perf", "multi", "improvement",
+ crypto_hashes_per_second / base_hashes_per_second,
+ "times", true);
+}
« 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