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

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

Issue 10790041: Add IDB perf tests for random read, with and without an index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix index creation and db deletion [but comment out deletion]. 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 6
7 function testCreateKeysInStores( 7 function testCreateKeysInStores(
8 numKeys, numStores, payloadLength, onTestComplete) { 8 numKeys, numStores, payloadLength, onTestComplete) {
9 var testName = "testCreateKeysInStores_" + numKeys + "_" + numStores + "_" + 9 var testName = "testCreateKeysInStores_" + numKeys + "_" + numStores + "_" +
10 payloadLength; 10 payloadLength;
11 assert(numKeys >= 0); 11 assert(numKeys >= 0);
12 assert(numStores >= 1); 12 assert(numStores >= 1);
13 var objectStoreNames = []; 13 var objectStoreNames = [];
14 for (var i=0; i < numStores; ++i) { 14 for (var i=0; i < numStores; ++i) {
15 objectStoreNames.push("store " + i); 15 objectStoreNames.push("store " + i);
16 } 16 }
17 var value = stringOfLength(payloadLength); 17 var value = stringOfLength(payloadLength);
18 var start;
19 18
20 function onCreated(db) { 19 function onCreated(db) {
21 automation.setStatus("Constructing transaction."); 20 automation.setStatus("Constructing transaction.");
22 start = Date.now(); // Ignore the setup time for this test. 21 var cleanUpFunc = getCleanUpFunc(testName, Date.now(), onTestComplete);
jsbell 2012/07/26 18:23:30 Having the test start time recorded in the call to
ericu 2012/07/26 20:24:11 How about if I call it "getCompletionFunc" instead
23 var transaction = getTransaction(db, objectStoreNames, "readwrite", 22 var transaction = getTransaction(db, objectStoreNames, "readwrite",
24 function() { onTransactionComplete(db); }); 23 function() { cleanUpFunc(); });
25 for (var i in objectStoreNames) { 24 for (var i in objectStoreNames) {
26 var os = transaction.objectStore(objectStoreNames[i]); 25 var os = transaction.objectStore(objectStoreNames[i]);
27 assert(os); 26 assert(os);
28 for (var j = 0; j < numKeys; ++j) { 27 for (var j = 0; j < numKeys; ++j) {
29 os.put("key " + j, value); 28 os.put(value, "key " + j);
30 } 29 }
31 } 30 }
32 } 31 }
33 function onTransactionComplete(db) { 32 automation.setStatus("Creating database.");
34 var duration = Date.now() - start;
35 // Ignore the cleanup time for this test.
36 automation.addResult(testName, duration);
37 automation.setStatus("Deleting.");
38 deleteDatabase(db, onDeleted);
39 }
40 function onDeleted() {
41 automation.setStatus("Deleted.");
42 onTestComplete();
43 }
44 automation.setStatus("Creating.");
45 createDatabase(testName, objectStoreNames, onCreated, onError); 33 createDatabase(testName, objectStoreNames, onCreated, onError);
46 } 34 }
47 35
36 function testRandomReads(numKeys, numReadsPerTransaction, numTransactions,
37 useIndex, onTestComplete) {
38 var indexText = "_bare";
39 var indexName;
40 if (useIndex) {
41 indexText = "_index";
42 indexName = "index";
43 }
44 var testName = "testRandomReads_" + numKeys + "_" + numReadsPerTransaction +
45 "_" + numTransactions + indexText;
46 var numTransactionsLeft = numTransactions;
47 var storeName = "store";
48 var objectStoreNames = [storeName];
jsbell 2012/07/26 18:23:30 FYI, a single string is acceptable as well as an a
ericu 2012/07/26 20:24:11 I make it a consistent array everywhere so as to k
49 var numTransactionsRunning;
50
51 function getKey(i) {
52 return "key " + i;
53 }
54
55 function getValue(i) {
56 return "value " + i;
57 }
58
59 function onCreated(db) {
60 automation.setStatus("Setting up test database.");
61 var transaction = getTransaction(db, objectStoreNames, "readwrite",
62 function() { onSetupComplete(db); });
63 var os = transaction.objectStore(storeName);
64 assert(os);
65 for (var j = 0; j < numKeys; ++j) {
66 os.put(getValue(i), getKey(j));
67 }
68 }
69 var cleanUpFunc;
70 function onSetupComplete(db) {
71 automation.setStatus("Setup complete.");
72 runOneBatch(db);
73 cleanUpFunc = getCleanUpFunc(testName, Date.now(), onTestComplete);
74 }
75
76 function runOneBatch(db) {
77 if (numTransactionsLeft <= 0) {
78 return;
79 }
80 --numTransactionsLeft;
81 ++numTransactionsRunning;
82 var valuesToRead = numReadsPerTransaction;
83 var transaction = getTransaction(db, objectStoreNames, "readonly",
84 function() {
85 assert(!--numTransactionsRunning);
86 assert(!valuesToRead);
87 if (numTransactionsLeft <= 0) {
88 cleanUpFunc();
89 } else {
90 runOneBatch(db);
91 }
92 });
93
94 var queryObject = transaction.objectStore(storeName);
95 if (useIndex) {
96 queryObject = queryObject.index(indexName);
97 }
98 assert(queryObject);
99 for (var i = 0; i < numReadsPerTransaction; ++i) {
100 var rand = Math.floor(Math.random() * numKeys);
101 var request = queryObject.get(getKey(rand));
102 request.onerror = onError;
103 request.onsuccess = function () {
104 assert(valuesToRead--);
105 }
106 }
107 }
108
109 automation.setStatus("Creating database.");
110 var options = {};
111 if (useIndex) {
112 options.indexName = indexName;
113 options.indexKeyPath = "";
114 options.indexIsUnique = true;
115 options.indexIsMultiEntry = false;
116 }
117 createDatabase(testName, objectStoreNames, onCreated, onError, options);
jsbell 2012/07/26 18:23:30 Might be just a personal thing, but I find tests m
ericu 2012/07/26 20:24:11 I lean the opposite way, and always want everythin
dgrogan 2012/07/26 20:35:58 I like code order = execution order, possibly just
118 }
119
48 var tests = [ 120 var tests = [
49 [testCreateKeysInStores, 1, 1, 1], 121 [testCreateKeysInStores, 1, 1, 1],
50 [testCreateKeysInStores, 100, 1, 1], 122 [testCreateKeysInStores, 100, 1, 1],
51 [testCreateKeysInStores, 1, 100, 1], 123 [testCreateKeysInStores, 1, 100, 1],
52 [testCreateKeysInStores, 100, 1, 100000] 124 [testCreateKeysInStores, 100, 1, 10000],
125 [testRandomReads, 1000, 5, 50, false],
jsbell 2012/07/26 18:23:30 For readability, maybe define a "const" (var kUseI
ericu 2012/07/26 20:24:11 Good idea; done.
126 [testRandomReads, 1000, 50, 5, false],
127 [testRandomReads, 5000, 50, 5, false],
128 [testRandomReads, 1000, 5, 50, true],
129 [testRandomReads, 1000, 50, 5, true],
130 [testRandomReads, 5000, 50, 5, true]
53 ]; 131 ];
54 132
55 var currentTest = 0; 133 var currentTest = 0;
56 134
57 function runNextTest() { 135 function runNextTest() {
58 if (currentTest < tests.length) { 136 if (currentTest < tests.length) {
59 var test = tests[currentTest++].slice(); 137 var test = tests[currentTest++].slice();
60 var f = test.shift(); 138 var f = test.shift();
61 test.push(runNextTest); 139 test.push(runNextTest);
62 f.apply(null, test); 140 f.apply(null, test);
63 } else { 141 } else {
64 onAllTestsComplete(); 142 onAllTestsComplete();
65 } 143 }
66 } 144 }
67 145
68 function onAllTestsComplete() { 146 function onAllTestsComplete() {
69 var overallDuration = Date.now() - overallTestStartTime; 147 var overallDuration = Date.now() - overallTestStartTime;
70 automation.addResult("OverallTestDuration", overallDuration); 148 automation.addResult("OverallTestDuration", overallDuration);
71 automation.setDone(); 149 automation.setDone();
72 } 150 }
73 151
74 function test() { 152 function test() {
75 runNextTest(); 153 runNextTest();
76 } 154 }
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