| 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);
|
| +}
|
|
|