OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 return GURL(base::StringPrintf("%s%d", prefix, i)); | 33 return GURL(base::StringPrintf("%s%d", prefix, i)); |
34 } | 34 } |
35 | 35 |
36 // We have no slaves, so all methods on this listener are a no-ops. | 36 // We have no slaves, so all methods on this listener are a no-ops. |
37 class DummyVisitedLinkEventListener : public VisitedLinkMaster::Listener { | 37 class DummyVisitedLinkEventListener : public VisitedLinkMaster::Listener { |
38 public: | 38 public: |
39 DummyVisitedLinkEventListener() {} | 39 DummyVisitedLinkEventListener() {} |
40 virtual void NewTable(base::SharedMemory* table) OVERRIDE {} | 40 virtual void NewTable(base::SharedMemory* table) OVERRIDE {} |
41 virtual void Add(VisitedLinkCommon::Fingerprint) OVERRIDE {} | 41 virtual void Add(VisitedLinkCommon::Fingerprint) OVERRIDE {} |
42 virtual void Reset() OVERRIDE {} | 42 virtual void Reset() OVERRIDE {} |
43 | |
44 static DummyVisitedLinkEventListener* GetInstance() { | |
45 static DummyVisitedLinkEventListener instance; | |
46 return &instance; | |
47 } | |
48 }; | 43 }; |
49 | 44 |
50 | 45 |
51 // this checks IsVisited for the URLs starting with the given prefix and | 46 // this checks IsVisited for the URLs starting with the given prefix and |
52 // within the given range | 47 // within the given range |
53 void CheckVisited(VisitedLinkMaster& master, const char* prefix, | 48 void CheckVisited(VisitedLinkMaster& master, const char* prefix, |
54 int begin, int end) { | 49 int begin, int end) { |
55 for (int i = begin; i < end; i++) | 50 for (int i = begin; i < end; i++) |
56 master.IsVisited(TestURL(prefix, i)); | 51 master.IsVisited(TestURL(prefix, i)); |
57 } | 52 } |
(...skipping 19 matching lines...) Expand all Loading... | |
77 | 72 |
78 } // namespace | 73 } // namespace |
79 | 74 |
80 // 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 |
81 // 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 |
82 // 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 |
83 // 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 |
84 // 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. |
85 TEST_F(VisitedLink, TestAddAndQuery) { | 80 TEST_F(VisitedLink, TestAddAndQuery) { |
86 // init | 81 // init |
87 VisitedLinkMaster master(DummyVisitedLinkEventListener::GetInstance(), | 82 VisitedLinkMaster master(new DummyVisitedLinkEventListener(), |
boliu
2013/03/31 17:30:03
nit: No need for () here and below
| |
88 NULL, true, true, db_path_, 0); | 83 NULL, true, true, db_path_, 0); |
89 ASSERT_TRUE(master.Init()); | 84 ASSERT_TRUE(master.Init()); |
90 | 85 |
91 PerfTimeLogger timer("Visited_link_add_and_query"); | 86 PerfTimeLogger timer("Visited_link_add_and_query"); |
92 | 87 |
93 // first check without anything in the table | 88 // first check without anything in the table |
94 CheckVisited(master, added_prefix, 0, add_count); | 89 CheckVisited(master, added_prefix, 0, add_count); |
95 | 90 |
96 // now fill half the table | 91 // now fill half the table |
97 const int half_size = add_count / 2; | 92 const int half_size = add_count / 2; |
(...skipping 10 matching lines...) Expand all Loading... | |
108 CheckVisited(master, added_prefix, 0, add_count); | 103 CheckVisited(master, added_prefix, 0, add_count); |
109 CheckVisited(master, unadded_prefix, 0, add_count); | 104 CheckVisited(master, unadded_prefix, 0, add_count); |
110 } | 105 } |
111 | 106 |
112 // Tests how long it takes to write and read a large database to and from disk. | 107 // Tests how long it takes to write and read a large database to and from disk. |
113 TEST_F(VisitedLink, TestLoad) { | 108 TEST_F(VisitedLink, TestLoad) { |
114 // create a big DB | 109 // create a big DB |
115 { | 110 { |
116 PerfTimeLogger table_initialization_timer("Table_initialization"); | 111 PerfTimeLogger table_initialization_timer("Table_initialization"); |
117 | 112 |
118 VisitedLinkMaster master(DummyVisitedLinkEventListener::GetInstance(), | 113 VisitedLinkMaster master(new DummyVisitedLinkEventListener(), |
119 NULL, true, true, db_path_, 0); | 114 NULL, true, true, db_path_, 0); |
120 | 115 |
121 // time init with empty table | 116 // time init with empty table |
122 PerfTimeLogger initTimer("Empty_visited_link_init"); | 117 PerfTimeLogger initTimer("Empty_visited_link_init"); |
123 bool success = master.Init(); | 118 bool success = master.Init(); |
124 initTimer.Done(); | 119 initTimer.Done(); |
125 ASSERT_TRUE(success); | 120 ASSERT_TRUE(success); |
126 | 121 |
127 // add a bunch of stuff | 122 // add a bunch of stuff |
128 // TODO(maruel): This is very inefficient because the file gets rewritten | 123 // TODO(maruel): This is very inefficient because the file gets rewritten |
(...skipping 17 matching lines...) Expand all Loading... | |
146 std::vector<double> cold_load_times; | 141 std::vector<double> cold_load_times; |
147 std::vector<double> hot_load_times; | 142 std::vector<double> hot_load_times; |
148 for (int i = 0; i < load_count; i++) { | 143 for (int i = 0; i < load_count; i++) { |
149 // make sure the file has to be re-loaded | 144 // make sure the file has to be re-loaded |
150 file_util::EvictFileFromSystemCache(db_path_); | 145 file_util::EvictFileFromSystemCache(db_path_); |
151 | 146 |
152 // cold load (no OS cache, hopefully) | 147 // cold load (no OS cache, hopefully) |
153 { | 148 { |
154 PerfTimer cold_timer; | 149 PerfTimer cold_timer; |
155 | 150 |
156 VisitedLinkMaster master(DummyVisitedLinkEventListener::GetInstance(), | 151 VisitedLinkMaster master(new DummyVisitedLinkEventListener(), |
157 NULL, | 152 NULL, |
158 true, | 153 true, |
159 true, | 154 true, |
160 db_path_, | 155 db_path_, |
161 0); | 156 0); |
162 bool success = master.Init(); | 157 bool success = master.Init(); |
163 TimeDelta elapsed = cold_timer.Elapsed(); | 158 TimeDelta elapsed = cold_timer.Elapsed(); |
164 ASSERT_TRUE(success); | 159 ASSERT_TRUE(success); |
165 | 160 |
166 cold_load_times.push_back(elapsed.InMillisecondsF()); | 161 cold_load_times.push_back(elapsed.InMillisecondsF()); |
167 } | 162 } |
168 | 163 |
169 // hot load (with OS caching the file in memory) | 164 // hot load (with OS caching the file in memory) |
170 { | 165 { |
171 PerfTimer hot_timer; | 166 PerfTimer hot_timer; |
172 | 167 |
173 VisitedLinkMaster master(DummyVisitedLinkEventListener::GetInstance(), | 168 VisitedLinkMaster master(new DummyVisitedLinkEventListener(), |
174 NULL, | 169 NULL, |
175 true, | 170 true, |
176 true, | 171 true, |
177 db_path_, | 172 db_path_, |
178 0); | 173 0); |
179 bool success = master.Init(); | 174 bool success = master.Init(); |
180 TimeDelta elapsed = hot_timer.Elapsed(); | 175 TimeDelta elapsed = hot_timer.Elapsed(); |
181 ASSERT_TRUE(success); | 176 ASSERT_TRUE(success); |
182 | 177 |
183 hot_load_times.push_back(elapsed.InMillisecondsF()); | 178 hot_load_times.push_back(elapsed.InMillisecondsF()); |
(...skipping 11 matching lines...) Expand all Loading... | |
195 cold_sum += cold_load_times[i]; | 190 cold_sum += cold_load_times[i]; |
196 hot_sum += hot_load_times[i]; | 191 hot_sum += hot_load_times[i]; |
197 } | 192 } |
198 LogPerfResult("Visited_link_cold_load_time", | 193 LogPerfResult("Visited_link_cold_load_time", |
199 cold_sum / cold_load_times.size(), "ms"); | 194 cold_sum / cold_load_times.size(), "ms"); |
200 LogPerfResult("Visited_link_hot_load_time", | 195 LogPerfResult("Visited_link_hot_load_time", |
201 hot_sum / hot_load_times.size(), "ms"); | 196 hot_sum / hot_load_times.size(), "ms"); |
202 } | 197 } |
203 | 198 |
204 } // namespace components | 199 } // namespace components |
OLD | NEW |