Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/rand_util.h" | 5 #include "base/rand_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/logging.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/time/time.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 14 |
| 12 namespace { | 15 namespace { |
| 13 | 16 |
| 14 const int kIntMin = std::numeric_limits<int>::min(); | 17 const int kIntMin = std::numeric_limits<int>::min(); |
| 15 const int kIntMax = std::numeric_limits<int>::max(); | 18 const int kIntMax = std::numeric_limits<int>::max(); |
| 16 | 19 |
| 17 } // namespace | 20 } // namespace |
| 18 | 21 |
| 19 TEST(RandUtilTest, SameMinAndMax) { | 22 TEST(RandUtilTest, SameMinAndMax) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 uint64 value = base::RandUint64(); | 116 uint64 value = base::RandUint64(); |
| 114 found_ones |= value; | 117 found_ones |= value; |
| 115 found_zeros &= value; | 118 found_zeros &= value; |
| 116 | 119 |
| 117 if (found_zeros == kAllZeros && found_ones == kAllOnes) | 120 if (found_zeros == kAllZeros && found_ones == kAllOnes) |
| 118 return; | 121 return; |
| 119 } | 122 } |
| 120 | 123 |
| 121 FAIL() << "Didn't achieve all bit values in maximum number of tries."; | 124 FAIL() << "Didn't achieve all bit values in maximum number of tries."; |
| 122 } | 125 } |
| 126 | |
| 127 TEST(RandUtilTest, DISABLED_RandBytesPerf) { | |
|
wtc
2014/01/22 22:29:09
We should document why this test is DISABLED.
DaleCurtis
2014/01/22 22:54:14
Done.
| |
| 128 // Benchmark the performance of |kTestIterations| of RandBytes() using a | |
| 129 // buffer size of |kTestBufferSize|. | |
| 130 const int kTestIterations = 10; | |
| 131 const size_t kTestBufferSize = 1 * 1024 * 1024; | |
| 132 | |
| 133 scoped_ptr<uint8[]> buffer(new uint8[kTestBufferSize]); | |
| 134 const base::TimeTicks now = base::TimeTicks::HighResNow(); | |
| 135 for (int i = 0; i < kTestIterations; ++i) | |
| 136 base::RandBytes(buffer.get(), kTestBufferSize); | |
| 137 const base::TimeTicks end = base::TimeTicks::HighResNow(); | |
| 138 | |
| 139 LOG(INFO) << "RandBytes(" << kTestBufferSize << ") took: " | |
| 140 << (end - now).InMicroseconds() << "µs"; | |
| 141 } | |
| OLD | NEW |