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

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: Simplify NaCl. 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
Index: base/rand_util_unittest.cc
diff --git a/base/rand_util_unittest.cc b/base/rand_util_unittest.cc
index e0e85ecaa91a6d38e63e57397e80a42848a3cdc5..81281dba9336f44aa1d30fb5958000745d681385 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,19 @@ TEST(RandUtilTest, RandUint64ProducesBothValuesOfAllBits) {
FAIL() << "Didn't achieve all bit values in maximum number of tries.";
}
+
+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.
+ // 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";
+}

Powered by Google App Engine
This is Rietveld 408576698