| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/perftimer.h" | 10 #include "base/perftimer.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 for (int i = 0; i < 300000; i++) { | 150 for (int i = 0; i < 300000; i++) { |
| 151 std::string key = GenerateKey(true); | 151 std::string key = GenerateKey(true); |
| 152 disk_cache::Hash(key); | 152 disk_cache::Hash(key); |
| 153 } | 153 } |
| 154 timer.Done(); | 154 timer.Done(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 TEST_F(DiskCacheTest, CacheBackendPerformance) { | 157 TEST_F(DiskCacheTest, CacheBackendPerformance) { |
| 158 MessageLoopForIO message_loop; | 158 MessageLoopForIO message_loop; |
| 159 | 159 |
| 160 std::wstring path_wstring = GetCachePath(); | 160 ScopedTestCache test_cache; |
| 161 ASSERT_TRUE(DeleteCache(path_wstring.c_str())); | 161 disk_cache::Backend* cache = |
| 162 disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path_wstring, | 162 disk_cache::CreateCacheBackend(test_cache.path_wstring(), false, 0); |
| 163 false, 0); | |
| 164 ASSERT_TRUE(NULL != cache); | 163 ASSERT_TRUE(NULL != cache); |
| 165 | 164 |
| 166 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 165 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
| 167 srand(seed); | 166 srand(seed); |
| 168 | 167 |
| 169 TestEntries entries; | 168 TestEntries entries; |
| 170 int num_entries = 1000; | 169 int num_entries = 1000; |
| 171 | 170 |
| 172 int ret = TimeWrite(num_entries, cache, &entries); | 171 int ret = TimeWrite(num_entries, cache, &entries); |
| 173 EXPECT_EQ(ret, g_cache_tests_received); | 172 EXPECT_EQ(ret, g_cache_tests_received); |
| 174 | 173 |
| 175 MessageLoop::current()->RunAllPending(); | 174 MessageLoop::current()->RunAllPending(); |
| 176 delete cache; | 175 delete cache; |
| 177 | 176 |
| 178 FilePath path = FilePath::FromWStringHack(path_wstring); | 177 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
| 178 test_cache.path().AppendASCII("index"))); |
| 179 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
| 180 test_cache.path().AppendASCII("data_0"))); |
| 181 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
| 182 test_cache.path().AppendASCII("data_1"))); |
| 183 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
| 184 test_cache.path().AppendASCII("data_2"))); |
| 185 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
| 186 test_cache.path().AppendASCII("data_3"))); |
| 179 | 187 |
| 180 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 188 cache = disk_cache::CreateCacheBackend(test_cache.path_wstring(), false, 0); |
| 181 path.AppendASCII("index"))); | |
| 182 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | |
| 183 path.AppendASCII("data_0"))); | |
| 184 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | |
| 185 path.AppendASCII("data_1"))); | |
| 186 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | |
| 187 path.AppendASCII("data_2"))); | |
| 188 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | |
| 189 path.AppendASCII("data_3"))); | |
| 190 | |
| 191 cache = disk_cache::CreateCacheBackend(path_wstring, false, 0); | |
| 192 ASSERT_TRUE(NULL != cache); | 189 ASSERT_TRUE(NULL != cache); |
| 193 | 190 |
| 194 ret = TimeRead(num_entries, cache, entries, true); | 191 ret = TimeRead(num_entries, cache, entries, true); |
| 195 EXPECT_EQ(ret, g_cache_tests_received); | 192 EXPECT_EQ(ret, g_cache_tests_received); |
| 196 | 193 |
| 197 ret = TimeRead(num_entries, cache, entries, false); | 194 ret = TimeRead(num_entries, cache, entries, false); |
| 198 EXPECT_EQ(ret, g_cache_tests_received); | 195 EXPECT_EQ(ret, g_cache_tests_received); |
| 199 | 196 |
| 200 MessageLoop::current()->RunAllPending(); | 197 MessageLoop::current()->RunAllPending(); |
| 201 delete cache; | 198 delete cache; |
| 202 } | 199 } |
| 203 | 200 |
| 204 // Creating and deleting "entries" on a block-file is something quite frequent | 201 // Creating and deleting "entries" on a block-file is something quite frequent |
| 205 // (after all, almost everything is stored on block files). The operation is | 202 // (after all, almost everything is stored on block files). The operation is |
| 206 // almost free when the file is empty, but can be expensive if the file gets | 203 // almost free when the file is empty, but can be expensive if the file gets |
| 207 // fragmented, or if we have multiple files. This test measures that scenario, | 204 // fragmented, or if we have multiple files. This test measures that scenario, |
| 208 // by using multiple, highly fragmented files. | 205 // by using multiple, highly fragmented files. |
| 209 TEST_F(DiskCacheTest, BlockFilesPerformance) { | 206 TEST_F(DiskCacheTest, BlockFilesPerformance) { |
| 210 MessageLoopForIO message_loop; | 207 MessageLoopForIO message_loop; |
| 211 std::wstring path = GetCachePath(); | |
| 212 ASSERT_TRUE(DeleteCache(path.c_str())); | |
| 213 | 208 |
| 214 disk_cache::BlockFiles files(path); | 209 ScopedTestCache test_cache; |
| 210 |
| 211 disk_cache::BlockFiles files(test_cache.path_wstring()); |
| 215 ASSERT_TRUE(files.Init(true)); | 212 ASSERT_TRUE(files.Init(true)); |
| 216 | 213 |
| 217 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 214 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
| 218 srand(seed); | 215 srand(seed); |
| 219 | 216 |
| 220 const int kNumEntries = 60000; | 217 const int kNumEntries = 60000; |
| 221 int32 buffer[kNumEntries]; | 218 int32 buffer[kNumEntries]; |
| 222 memset(buffer, 0, sizeof(buffer)); | 219 memset(buffer, 0, sizeof(buffer)); |
| 223 disk_cache::Addr* address = reinterpret_cast<disk_cache::Addr*>(buffer); | 220 disk_cache::Addr* address = reinterpret_cast<disk_cache::Addr*>(buffer); |
| 224 ASSERT_EQ(sizeof(*address), sizeof(*buffer)); | 221 ASSERT_EQ(sizeof(*address), sizeof(*buffer)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 240 entry = 0; | 237 entry = 0; |
| 241 | 238 |
| 242 files.DeleteBlock(address[entry], false); | 239 files.DeleteBlock(address[entry], false); |
| 243 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(), | 240 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(), |
| 244 &address[entry])); | 241 &address[entry])); |
| 245 } | 242 } |
| 246 | 243 |
| 247 timer2.Done(); | 244 timer2.Done(); |
| 248 MessageLoop::current()->RunAllPending(); | 245 MessageLoop::current()->RunAllPending(); |
| 249 } | 246 } |
| OLD | NEW |