| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <memory> |
| 12 | 13 |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 const int kIntMin = std::numeric_limits<int>::min(); | 20 const int kIntMin = std::numeric_limits<int>::min(); |
| 21 const int kIntMax = std::numeric_limits<int>::max(); | 21 const int kIntMax = std::numeric_limits<int>::max(); |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 // Benchmark test for RandBytes(). Disabled since it's intentionally slow and | 137 // Benchmark test for RandBytes(). Disabled since it's intentionally slow and |
| 138 // does not test anything that isn't already tested by the existing RandBytes() | 138 // does not test anything that isn't already tested by the existing RandBytes() |
| 139 // tests. | 139 // tests. |
| 140 TEST(RandUtilTest, DISABLED_RandBytesPerf) { | 140 TEST(RandUtilTest, DISABLED_RandBytesPerf) { |
| 141 // Benchmark the performance of |kTestIterations| of RandBytes() using a | 141 // Benchmark the performance of |kTestIterations| of RandBytes() using a |
| 142 // buffer size of |kTestBufferSize|. | 142 // buffer size of |kTestBufferSize|. |
| 143 const int kTestIterations = 10; | 143 const int kTestIterations = 10; |
| 144 const size_t kTestBufferSize = 1 * 1024 * 1024; | 144 const size_t kTestBufferSize = 1 * 1024 * 1024; |
| 145 | 145 |
| 146 scoped_ptr<uint8_t[]> buffer(new uint8_t[kTestBufferSize]); | 146 std::unique_ptr<uint8_t[]> buffer(new uint8_t[kTestBufferSize]); |
| 147 const base::TimeTicks now = base::TimeTicks::Now(); | 147 const base::TimeTicks now = base::TimeTicks::Now(); |
| 148 for (int i = 0; i < kTestIterations; ++i) | 148 for (int i = 0; i < kTestIterations; ++i) |
| 149 base::RandBytes(buffer.get(), kTestBufferSize); | 149 base::RandBytes(buffer.get(), kTestBufferSize); |
| 150 const base::TimeTicks end = base::TimeTicks::Now(); | 150 const base::TimeTicks end = base::TimeTicks::Now(); |
| 151 | 151 |
| 152 LOG(INFO) << "RandBytes(" << kTestBufferSize << ") took: " | 152 LOG(INFO) << "RandBytes(" << kTestBufferSize << ") took: " |
| 153 << (end - now).InMicroseconds() << "µs"; | 153 << (end - now).InMicroseconds() << "µs"; |
| 154 } | 154 } |
| OLD | NEW |