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

Side by Side Diff: chrome/test/data/indexeddb/perf_test.js

Issue 10854046: Add cache test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add cache test length variants Created 8 years, 4 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 var overallTestStartTime = Date.now(); 5 var overallTestStartTime = Date.now();
6 var kUseIndex = true; 6 var kUseIndex = true;
7 var kDontUseIndex = false; 7 var kDontUseIndex = false;
8 var kReadKeysOnly = true; 8 var kReadKeysOnly = true;
9 var kReadDataToo = false; 9 var kReadDataToo = false;
10 var kWriteToo = true; 10 var kWriteToo = true;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 [testSporadicWrites, 5, 0], 70 [testSporadicWrites, 5, 0],
71 // Make large batches of random writes into a store, triggered by periodic 71 // Make large batches of random writes into a store, triggered by periodic
72 // setTimeout calls. 72 // setTimeout calls.
73 [testSporadicWrites, 500, 0], 73 [testSporadicWrites, 500, 0],
74 // Make batches of random writes into a store with many indices, triggered by 74 // Make batches of random writes into a store with many indices, triggered by
75 // periodic setTimeout calls. 75 // periodic setTimeout calls.
76 [testSporadicWrites, 5, 10], 76 [testSporadicWrites, 5, 10],
77 // Make large batches of random writes into a store with many indices, triggered 77 // Make large batches of random writes into a store with many indices, triggered
78 // by periodic setTimeout calls. 78 // by periodic setTimeout calls.
79 [testSporadicWrites, 500, 10], 79 [testSporadicWrites, 500, 10],
80 // Make a small bunch of batches of reads of the same keys from an object store.
81 [testReadCache, 10, kDontUseIndex],
82 // Make a bunch of batches of reads of the same keys from an index.
83 [testReadCache, 50, kUseIndex],
84 // Make a small bunch of batches of reads of the same keys from an object store.
85 [testReadCache, 10, kDontUseIndex],
86 // Make a bunch of batches of reads of the same keys from an index.
87 [testReadCache, 50, kUseIndex],
80 // Create and delete an index on a store that already contains data [produces 88 // Create and delete an index on a store that already contains data [produces
81 // a timing result for each of creation and deletion]. 89 // a timing result for each of creation and deletion].
82 [testCreateAndDeleteIndex, 5000] 90 [testCreateAndDeleteIndex, 5000]
83 ]; 91 ];
84 92
85 var currentTest = 0; 93 var currentTest = 0;
86 94
87 function test() { 95 function test() {
88 runNextTest(); 96 runNextTest();
89 } 97 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 244 }
237 }); 245 });
238 246
239 getRandomValues(transaction, objectStoreNames, numReadsPerTransaction, 247 getRandomValues(transaction, objectStoreNames, numReadsPerTransaction,
240 numKeys, indexName); 248 numKeys, indexName);
241 putRandomValues(transaction, objectStoreNames, numWritesPerTransaction, 249 putRandomValues(transaction, objectStoreNames, numWritesPerTransaction,
242 numKeys); 250 numKeys);
243 } 251 }
244 } 252 }
245 253
254 function testReadCache(numTransactions, useIndexForReads, onTestComplete) {
255 var numKeys = 10000;
256 var numReadsPerTransaction = 50;
257 var numTransactionsLeft = numTransactions;
258 var indexName;
259 if (useIndexForReads)
260 indexName = "index";
261 var testName = getDisplayName(arguments);
262 var objectStoreNames = ["store"];
263 var numTransactionsRunning;
264 var keys = [];
265
266 for (var i=0; i < numReadsPerTransaction; ++i) {
267 keys.push(getSimpleKey(Math.floor(Math.random() * numKeys)));
268 }
269
270 automation.setStatus("Creating database.");
271 var options;
272 if (useIndexForReads) {
273 options = [{
274 indexName: indexName,
275 indexKeyPath: "",
276 indexIsUnique: false,
277 indexIsMultiEntry: false,
278 }];
279 }
280 createDatabase(testName, objectStoreNames, onCreated, onError, options);
281
282 function onCreated(db) {
283 automation.setStatus("Setting up test database.");
284 var transaction = getTransaction(db, objectStoreNames, "readwrite",
285 function() { onSetupComplete(db); });
286 putLinearValues(transaction, objectStoreNames, numKeys, getSimpleKey,
287 function () { return "test value"; });
jsbell 2012/08/09 17:58:18 Nit: space between function keyword and ()
ericu 2012/08/15 17:56:22 Done.
288 }
289
290 var completionFunc;
291 function onSetupComplete(db) {
292 automation.setStatus("Setup complete.");
293 completionFunc =
294 getCompletionFunc(db, testName, Date.now(), onTestComplete);
295 runOneBatch(db);
296 }
297
298 function runOneBatch(db) {
jsbell 2012/08/09 17:58:18 This runOneBatch() pattern seems to be re-used in
ericu 2012/08/15 17:56:22 It's used in 3 places, but one is actually differe
299 if (numTransactionsLeft <= 0) {
300 return;
301 }
302 --numTransactionsLeft;
303 ++numTransactionsRunning;
304 var transaction = getTransaction(db, objectStoreNames, "readonly",
305 function() {
306 assert(!--numTransactionsRunning);
307 if (numTransactionsLeft <= 0) {
308 completionFunc();
309 } else {
310 runOneBatch(db);
311 }
312 });
313
314 getSpecificValues(transaction, objectStoreNames, indexName, keys);
315 }
316 }
317
246 function testCreateAndDeleteIndex(numKeys, onTestComplete) { 318 function testCreateAndDeleteIndex(numKeys, onTestComplete) {
247 var testName = getDisplayName(arguments); 319 var testName = getDisplayName(arguments);
248 var objectStoreNames = ["store"]; 320 var objectStoreNames = ["store"];
249 321
250 automation.setStatus("Creating database."); 322 automation.setStatus("Creating database.");
251 createDatabase(testName, objectStoreNames, onCreated, onError); 323 createDatabase(testName, objectStoreNames, onCreated, onError);
252 324
253 var startTime; 325 var startTime;
254 function onCreated(db) { 326 function onCreated(db) {
255 automation.setStatus("Initializing data."); 327 automation.setStatus("Initializing data.");
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 500
429 var mode = "readonly"; 501 var mode = "readonly";
430 if (numWritesPerTransaction) 502 if (numWritesPerTransaction)
431 mode = "readwrite"; 503 mode = "readwrite";
432 504
433 var transaction = getTransaction(db, objectStoreNames, mode, batchComplete); 505 var transaction = getTransaction(db, objectStoreNames, mode, batchComplete);
434 putRandomValues(transaction, objectStoreNames, numWritesPerTransaction, 506 putRandomValues(transaction, objectStoreNames, numWritesPerTransaction,
435 numKeys); 507 numKeys);
436 } 508 }
437 } 509 }
OLDNEW
« chrome/test/data/indexeddb/perf_shared.js ('K') | « chrome/test/data/indexeddb/perf_shared.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698