Chromium Code Reviews| 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 <limits> | 5 #include <limits> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/hash.h" | 12 #include "base/hash.h" |
| 13 #include "base/process/process_metrics.h" | 13 #include "base/process/process_metrics.h" |
| 14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/test/perf_time_logger.h" | 17 #include "base/test/perf_time_logger.h" |
| 18 #include "base/test/test_file_util.h" | 18 #include "base/test/test_file_util.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "net/base/cache_type.h" | 20 #include "net/base/cache_type.h" |
| 21 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
| 22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 #include "net/base/test_completion_callback.h" | 23 #include "net/base/test_completion_callback.h" |
| 24 #include "net/disk_cache/blockfile/backend_impl.h" | 24 #include "net/disk_cache/blockfile/backend_impl.h" |
| 25 #include "net/disk_cache/blockfile/block_files.h" | 25 #include "net/disk_cache/blockfile/block_files.h" |
| 26 #include "net/disk_cache/disk_cache.h" | 26 #include "net/disk_cache/disk_cache.h" |
| 27 #include "net/disk_cache/disk_cache_test_base.h" | 27 #include "net/disk_cache/disk_cache_test_base.h" |
| 28 #include "net/disk_cache/disk_cache_test_util.h" | 28 #include "net/disk_cache/disk_cache_test_util.h" |
| 29 #include "net/disk_cache/simple/simple_backend_impl.h" | 29 #include "net/disk_cache/simple/simple_backend_impl.h" |
| 30 #include "net/disk_cache/simple/simple_index.h" | |
| 31 #include "net/disk_cache/simple/simple_index_file.h" | |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "testing/platform_test.h" | 33 #include "testing/platform_test.h" |
| 32 | 34 |
| 33 using base::Time; | 35 using base::Time; |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 37 size_t MaybeGetMaxFds() { | 39 size_t MaybeGetMaxFds() { |
| 38 #if defined(OS_POSIX) | 40 #if defined(OS_POSIX) |
| 39 return base::GetMaxFds(); | 41 return base::GetMaxFds(); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 files.DeleteBlock(address[entry], false); | 301 files.DeleteBlock(address[entry], false); |
| 300 EXPECT_TRUE( | 302 EXPECT_TRUE( |
| 301 files.CreateBlock(disk_cache::RANKINGS, block_size, &address[entry])); | 303 files.CreateBlock(disk_cache::RANKINGS, block_size, &address[entry])); |
| 302 } | 304 } |
| 303 | 305 |
| 304 timer2.Done(); | 306 timer2.Done(); |
| 305 base::RunLoop().RunUntilIdle(); | 307 base::RunLoop().RunUntilIdle(); |
| 306 } | 308 } |
| 307 | 309 |
| 308 } // namespace | 310 } // namespace |
| 311 | |
| 312 namespace disk_cache { | |
| 313 | |
| 314 // Measures how quickly SimpleIndex can compute which entries to evict. | |
| 315 TEST(SimpleIndexPerfTest, EvictionPerformance) { | |
| 316 class NoOpDelegate : public disk_cache::SimpleIndexDelegate { | |
| 317 void DoomEntries(std::vector<uint64_t>* entry_hashes, | |
| 318 const net::CompletionCallback& callback) override {} | |
| 319 }; | |
| 320 | |
| 321 NoOpDelegate delegate; | |
| 322 disk_cache::SimpleIndex index(nullptr, &delegate, net::DISK_CACHE, nullptr); | |
| 323 | |
| 324 base::ElapsedTimer timer; | |
| 325 const int kEntries = 25000; | |
| 326 base::Time now(base::Time::Now()); | |
| 327 index.SetMaxSize(kEntries); | |
| 328 | |
| 329 for (int i = 0; i < kEntries; ++i) { | |
| 330 disk_cache::SimpleIndex::InsertInEntrySet( | |
| 331 i, disk_cache::EntryMetadata(now + base::TimeDelta::FromSeconds(i), 0u), | |
| 332 &index.entries_set_); | |
| 333 // Will trigger eviction once we are nearly full. | |
| 334 index.UpdateEntrySize(i, 1u); | |
| 335 } | |
| 336 | |
| 337 LOG(ERROR) << "Took:" << timer.Elapsed().InMillisecondsF() << "ms"; | |
|
pasko
2017/03/31 17:41:56
How stable are the numbers produced?
I think it i
Maks Orlovich
2017/03/31 19:01:29
Less stable now that you've asked about it :) (usu
pasko
2017/04/03 09:39:08
Reasons I can see:
1. with const iterations there
| |
| 338 } | |
| 339 | |
| 340 } // namespace disk_cache | |
| OLD | NEW |