Chromium Code Reviews| Index: net/disk_cache/disk_cache_perftest.cc |
| diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc |
| index daeb6770b91d5fe02c89141c183a8db13aa4aad6..f935780b5fbd5ec9e8583b157d545a8545456082 100644 |
| --- a/net/disk_cache/disk_cache_perftest.cc |
| +++ b/net/disk_cache/disk_cache_perftest.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/files/file_path.h" |
| #include "base/hash.h" |
| #include "base/process/process_metrics.h" |
| +#include "base/rand_util.h" |
| #include "base/run_loop.h" |
| #include "base/strings/string_util.h" |
| #include "base/test/perf_time_logger.h" |
| @@ -114,7 +115,7 @@ bool DiskCachePerfTest::TimeWrite() { |
| for (int i = 0; i < kNumEntries; i++) { |
| TestEntry entry; |
| entry.key = GenerateKey(true); |
| - entry.data_len = rand() % kBodySize; |
| + entry.data_len = base::RandInt(0, kBodySize); |
| entries_.push_back(entry); |
| disk_cache::Entry* cache_entry; |
| @@ -196,9 +197,6 @@ bool DiskCachePerfTest::TimeRead(WhatToRead what_to_read, |
| } |
| TEST_F(DiskCachePerfTest, BlockfileHashes) { |
| - int seed = static_cast<int>(Time::Now().ToInternalValue()); |
| - srand(seed); |
| - |
| base::PerfTimeLogger timer("Hash disk cache keys"); |
| for (int i = 0; i < 300000; i++) { |
| std::string key = GenerateKey(true); |
| @@ -270,7 +268,7 @@ TEST_F(DiskCachePerfTest, SimpleCacheBackendPerformance) { |
| int BlockSize() { |
| // We can use form 1 to 4 blocks. |
|
jkarlin
2016/11/15 12:18:29
While you're here..
s/form/from/
gavinp
2016/11/15 15:30:53
Done. Also removed the function; documented the ro
|
| - return (rand() & 0x3) + 1; |
| + return base::RandInt(1, 4); |
| } |
| // Creating and deleting "entries" on a block-file is something quite frequent |
| @@ -284,9 +282,6 @@ TEST_F(DiskCachePerfTest, BlockFilesPerformance) { |
| disk_cache::BlockFiles files(cache_path_); |
| ASSERT_TRUE(files.Init(true)); |
| - int seed = static_cast<int>(Time::Now().ToInternalValue()); |
| - srand(seed); |
| - |
| const int kNumBlocks = 60000; |
| disk_cache::Addr address[kNumBlocks]; |
| @@ -302,7 +297,8 @@ TEST_F(DiskCachePerfTest, BlockFilesPerformance) { |
| base::PerfTimeLogger timer2("Create and delete blocks"); |
| for (int i = 0; i < 200000; i++) { |
| - int entry = rand() * (kNumBlocks / RAND_MAX + 1); |
| + int entry = base::RandInt(0, kNumBlocks); |
|
jkarlin
2016/11/15 12:18:29
base::RandInt(0, kNumBlocks-1) since it's inclusiv
gavinp
2016/11/15 15:30:54
Done.
I can't believe these gymnastics. This is s
|
| + |
| if (entry >= kNumBlocks) |
|
jkarlin
2016/11/15 12:18:29
This condition should go.
gavinp
2016/11/15 15:30:54
Done.
|
| entry = 0; |