[M94 Dev][Tizen] Fix for errors for generating ninja files
[platform/framework/web/chromium-efl.git] / base / rand_util_perftest.cc
1 // Copyright 2021 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 #include "base/rand_util.h"
6 #include "base/time/time.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "testing/perf/perf_result_reporter.h"
9
10 namespace base {
11
12 namespace {
13
14 constexpr char kMetricPrefix[] = "RandUtil.";
15 constexpr char kThroughput[] = "throughput";
16
17 }  // namespace
18
19 TEST(RandUtilPerfTest, RandUint64) {
20   uint64_t inclusive_or = 0;
21   constexpr int kIterations = 1e7;
22
23   auto before = base::TimeTicks::Now();
24   for (int iter = 0; iter < kIterations; iter++) {
25     inclusive_or |= base::RandUint64();
26   }
27   auto after = base::TimeTicks::Now();
28
29   perf_test::PerfResultReporter reporter(kMetricPrefix, "RandUint64");
30   reporter.RegisterImportantMetric(kThroughput, "ns / iteration");
31
32   uint64_t nanos_per_iteration = (after - before).InNanoseconds() / kIterations;
33   reporter.AddResult("throughput", static_cast<size_t>(nanos_per_iteration));
34   ASSERT_NE(inclusive_or, static_cast<uint64_t>(0));
35 }
36
37 TEST(RandUtilPerfTest, InsecureRandomRandUint64) {
38   base::InsecureRandomGenerator gen;
39   gen.Seed();
40
41   uint64_t inclusive_or = 0;
42   constexpr int kIterations = 1e7;
43
44   auto before = base::TimeTicks::Now();
45   for (int iter = 0; iter < kIterations; iter++) {
46     inclusive_or |= gen.RandUint64();
47   }
48   auto after = base::TimeTicks::Now();
49
50   perf_test::PerfResultReporter reporter(kMetricPrefix,
51                                          "InsecureRandomRandUint64");
52   reporter.RegisterImportantMetric(kThroughput, "ns / iteration");
53
54   uint64_t nanos_per_iteration = (after - before).InNanoseconds() / kIterations;
55   reporter.AddResult("throughput", static_cast<size_t>(nanos_per_iteration));
56   ASSERT_NE(inclusive_or, static_cast<uint64_t>(0));
57 }
58
59 }  // namespace base