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

Side by Side Diff: base/rand_util_unittest.cc

Issue 140773006: Improve base::RandBytes() performance by 1.75x-2.10x on POSIX. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/rand_util_posix.cc ('k') | base/rand_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Benchmark test for RandBytes(). Disabled since it's intentionally slow and
128 // does not test anything that isn't already tested by the existing RandBytes()
129 // tests.
130 TEST(RandUtilTest, DISABLED_RandBytesPerf) {
131 // Benchmark the performance of |kTestIterations| of RandBytes() using a
132 // buffer size of |kTestBufferSize|.
133 const int kTestIterations = 10;
134 const size_t kTestBufferSize = 1 * 1024 * 1024;
135
136 scoped_ptr<uint8[]> buffer(new uint8[kTestBufferSize]);
137 const base::TimeTicks now = base::TimeTicks::HighResNow();
138 for (int i = 0; i < kTestIterations; ++i)
139 base::RandBytes(buffer.get(), kTestBufferSize);
140 const base::TimeTicks end = base::TimeTicks::HighResNow();
141
142 LOG(INFO) << "RandBytes(" << kTestBufferSize << ") took: "
143 << (end - now).InMicroseconds() << "µs";
144 }
OLDNEW
« no previous file with comments | « base/rand_util_posix.cc ('k') | base/rand_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698