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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/rand_util_posix.cc ('k') | base/rand_util_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/rand_util_unittest.cc
diff --git a/base/rand_util_unittest.cc b/base/rand_util_unittest.cc
index e0e85ecaa91a6d38e63e57397e80a42848a3cdc5..d26227505d05290707114dbd73afdafcf5f338d2 100644
--- a/base/rand_util_unittest.cc
+++ b/base/rand_util_unittest.cc
@@ -7,6 +7,9 @@
#include <algorithm>
#include <limits>
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -120,3 +123,22 @@ TEST(RandUtilTest, RandUint64ProducesBothValuesOfAllBits) {
FAIL() << "Didn't achieve all bit values in maximum number of tries.";
}
+
+// Benchmark test for RandBytes(). Disabled since it's intentionally slow and
+// does not test anything that isn't already tested by the existing RandBytes()
+// tests.
+TEST(RandUtilTest, DISABLED_RandBytesPerf) {
+ // Benchmark the performance of |kTestIterations| of RandBytes() using a
+ // buffer size of |kTestBufferSize|.
+ const int kTestIterations = 10;
+ const size_t kTestBufferSize = 1 * 1024 * 1024;
+
+ scoped_ptr<uint8[]> buffer(new uint8[kTestBufferSize]);
+ const base::TimeTicks now = base::TimeTicks::HighResNow();
+ for (int i = 0; i < kTestIterations; ++i)
+ base::RandBytes(buffer.get(), kTestBufferSize);
+ const base::TimeTicks end = base::TimeTicks::HighResNow();
+
+ LOG(INFO) << "RandBytes(" << kTestBufferSize << ") took: "
+ << (end - now).InMicroseconds() << "µs";
+}
« 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