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

Side by Side Diff: chrome/browser/visitedlink_perftest.cc

Issue 12893: Get rid of kPathSeparator on windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/url_fetcher_unittest.cc ('k') | chrome/browser/webdata/web_database_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/perftimer.h" 10 #include "base/perftimer.h"
(...skipping 16 matching lines...) Expand all
27 // Returns a URL with the given prefix and index 27 // Returns a URL with the given prefix and index
28 GURL TestURL(const char* prefix, int i) { 28 GURL TestURL(const char* prefix, int i) {
29 return GURL(StringPrintf("%s%d", prefix, i)); 29 return GURL(StringPrintf("%s%d", prefix, i));
30 } 30 }
31 31
32 // we have no slaves, so this broadcase is a NOP 32 // we have no slaves, so this broadcase is a NOP
33 VisitedLinkMaster::PostNewTableEvent DummyBroadcastNewTableEvent; 33 VisitedLinkMaster::PostNewTableEvent DummyBroadcastNewTableEvent;
34 void DummyBroadcastNewTableEvent(base::SharedMemory *table) { 34 void DummyBroadcastNewTableEvent(base::SharedMemory *table) {
35 } 35 }
36 36
37 // Call at the beginning of the test to retrieve the database name and to 37 // Call at the beginning of the test to retrieve the database name.
38 // delete any old databases left by previous unit tests. The input buffer 38 void InitDBName(std::wstring* db_name) {
39 // should be MAX_PATH long. 39 FilePath db_path;
40 void InitDBName(wchar_t* db_name) { 40 ASSERT_TRUE(file_util::GetCurrentDirectory(&db_path));
41 ASSERT_TRUE(GetCurrentDirectory(MAX_PATH, db_name)); 41 db_path = db_path.Append(FILE_PATH_LITERAL("TempVisitedLinks"));
42 if (db_name[wcslen(db_name) - 1] != file_util::kPathSeparator) 42 *db_name = db_path.ToWStringHack();
43 wcsncat_s(db_name, MAX_PATH, &file_util::kPathSeparator, 1);
44 wcscat_s(db_name, MAX_PATH, L"TempVisitedLinks");
45 } 43 }
46 44
47 // this checks IsVisited for the URLs starting with the given prefix and 45 // this checks IsVisited for the URLs starting with the given prefix and
48 // within the given range 46 // within the given range
49 void CheckVisited(VisitedLinkMaster& master, const char* prefix, 47 void CheckVisited(VisitedLinkMaster& master, const char* prefix,
50 int begin, int end) { 48 int begin, int end) {
51 for (int i = begin; i < end; i++) 49 for (int i = begin; i < end; i++)
52 master.IsVisited(TestURL(prefix, i)); 50 master.IsVisited(TestURL(prefix, i));
53 } 51 }
54 52
55 // Fills that master's table with URLs starting with the given prefix and 53 // Fills that master's table with URLs starting with the given prefix and
56 // within the given range 54 // within the given range
57 void FillTable(VisitedLinkMaster& master, const char* prefix, 55 void FillTable(VisitedLinkMaster& master, const char* prefix,
58 int begin, int end) { 56 int begin, int end) {
59 for (int i = begin; i < end; i++) 57 for (int i = begin; i < end; i++)
60 master.AddURL(TestURL(prefix, i)); 58 master.AddURL(TestURL(prefix, i));
61 } 59 }
62 60
63 class VisitedLink : public testing::Test { 61 class VisitedLink : public testing::Test {
64 protected: 62 protected:
65 wchar_t db_name_[MAX_PATH]; 63 std::wstring db_name_;
66 virtual void SetUp() { 64 virtual void SetUp() {
67 InitDBName(db_name_); 65 InitDBName(&db_name_);
68 DeleteFile(db_name_); 66 file_util::Delete(db_name_, false);
69 } 67 }
70 virtual void TearDown() { 68 virtual void TearDown() {
71 DeleteFile(db_name_); 69 file_util::Delete(db_name_, false);
72 } 70 }
73 }; 71 };
74 72
75 } // namespace 73 } // namespace
76 74
77 // This test tests adding many things to a database, and how long it takes 75 // This test tests adding many things to a database, and how long it takes
78 // to query the database with different numbers of things in it. The time 76 // to query the database with different numbers of things in it. The time
79 // is the total time to do all the operations, and as such, it is only 77 // is the total time to do all the operations, and as such, it is only
80 // useful for a regression test. If there is a regression, it might be 78 // useful for a regression test. If there is a regression, it might be
81 // useful to make another set of tests to test these things in isolation. 79 // useful to make another set of tests to test these things in isolation.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 136 }
139 137
140 // test loading the DB back, we do this several times since the flushing is 138 // test loading the DB back, we do this several times since the flushing is
141 // not very reliable. 139 // not very reliable.
142 const int load_count = 5; 140 const int load_count = 5;
143 std::vector<double> cold_load_times; 141 std::vector<double> cold_load_times;
144 std::vector<double> hot_load_times; 142 std::vector<double> hot_load_times;
145 for (int i = 0; i < load_count; i++) 143 for (int i = 0; i < load_count; i++)
146 { 144 {
147 // make sure the file has to be re-loaded 145 // make sure the file has to be re-loaded
148 file_util::EvictFileFromSystemCache(db_name_); 146 file_util::EvictFileFromSystemCache(db_name_.c_str());
149 147
150 // cold load (no OS cache, hopefully) 148 // cold load (no OS cache, hopefully)
151 { 149 {
152 PerfTimer cold_timer; 150 PerfTimer cold_timer;
153 151
154 VisitedLinkMaster master(NULL, DummyBroadcastNewTableEvent, NULL, true, 152 VisitedLinkMaster master(NULL, DummyBroadcastNewTableEvent, NULL, true,
155 db_name_, 0); 153 db_name_, 0);
156 bool success = master.Init(); 154 bool success = master.Init();
157 TimeDelta elapsed = cold_timer.Elapsed(); 155 TimeDelta elapsed = cold_timer.Elapsed();
158 ASSERT_TRUE(success); 156 ASSERT_TRUE(success);
(...skipping 25 matching lines...) Expand all
184 for (int i = 0; i < static_cast<int>(cold_load_times.size()); i++) { 182 for (int i = 0; i < static_cast<int>(cold_load_times.size()); i++) {
185 cold_sum += cold_load_times[i]; 183 cold_sum += cold_load_times[i];
186 hot_sum += hot_load_times[i]; 184 hot_sum += hot_load_times[i];
187 } 185 }
188 LogPerfResult("Visited_link_cold_load_time", 186 LogPerfResult("Visited_link_cold_load_time",
189 cold_sum / cold_load_times.size(), "ms"); 187 cold_sum / cold_load_times.size(), "ms");
190 LogPerfResult("Visited_link_hot_load_time", 188 LogPerfResult("Visited_link_hot_load_time",
191 hot_sum / hot_load_times.size(), "ms"); 189 hot_sum / hot_load_times.size(), "ms");
192 } 190 }
193 191
OLDNEW
« no previous file with comments | « chrome/browser/url_fetcher_unittest.cc ('k') | chrome/browser/webdata/web_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698