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

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

Issue 10803029: Add read/write tests, index creation/deletion test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged out, fixed indexed writes. 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 = getDisplayName(arguments);
10 payloadLength;
11 assert(numKeys >= 0); 10 assert(numKeys >= 0);
12 assert(numStores >= 1); 11 assert(numStores >= 1);
13 var objectStoreNames = []; 12 var objectStoreNames = [];
14 for (var i=0; i < numStores; ++i) { 13 for (var i=0; i < numStores; ++i) {
15 objectStoreNames.push("store " + i); 14 objectStoreNames.push("store " + i);
16 } 15 }
17 var value = stringOfLength(payloadLength); 16 var value = stringOfLength(payloadLength);
17 function getValue() {
18 return value;
19 }
18 20
19 function onCreated(db) { 21 function onCreated(db) {
20 automation.setStatus("Constructing transaction."); 22 automation.setStatus("Constructing transaction.");
21 var cleanUpFunc = getCleanUpFunc(testName, Date.now(), onTestComplete); 23 var cleanUpFunc = getCleanUpFunc(testName, Date.now(), onTestComplete);
22 var transaction = getTransaction(db, objectStoreNames, "readwrite", 24 var transaction = getTransaction(db, objectStoreNames, "readwrite",
23 function() { cleanUpFunc(); }); 25 function() { cleanUpFunc(); });
24 for (var i in objectStoreNames) { 26 putLinearValues(transaction, objectStoreNames, numKeys, null, getValue);
25 var os = transaction.objectStore(objectStoreNames[i]);
26 assert(os);
27 for (var j = 0; j < numKeys; ++j) {
28 os.put(value, "key " + j);
29 }
30 }
31 } 27 }
32 automation.setStatus("Creating database."); 28 automation.setStatus("Creating database.");
33 createDatabase(testName, objectStoreNames, onCreated, onError); 29 createDatabase(testName, objectStoreNames, onCreated, onError);
34 } 30 }
35 31
36 function testRandomReads(numKeys, numReadsPerTransaction, numTransactions, 32 function testRandomReadsAndWrites(
37 useIndex, onTestComplete) { 33 numKeys, numReadsPerTransaction, numWritesPerTransaction, numTransactions,
38 var indexText = "_bare"; 34 useIndexForReads, onTestComplete) {
39 var indexName; 35 var indexName;
40 if (useIndex) { 36 if (useIndexForReads)
41 indexText = "_index";
42 indexName = "index"; 37 indexName = "index";
43 } 38 var testName = getDisplayName(arguments);
44 var testName = "testRandomReads_" + numKeys + "_" + numReadsPerTransaction +
45 "_" + numTransactions + indexText;
46 var numTransactionsLeft = numTransactions; 39 var numTransactionsLeft = numTransactions;
47 var storeName = "store"; 40 var objectStoreNames = ["store"];
48 var objectStoreNames = [storeName];
49 var numTransactionsRunning; 41 var numTransactionsRunning;
50 42
51 function getKey(i) {
52 return "key " + i;
53 }
54
55 function getValue(i) {
56 return "value " + i;
57 }
58
59 function onCreated(db) { 43 function onCreated(db) {
60 automation.setStatus("Setting up test database."); 44 automation.setStatus("Setting up test database.");
61 var transaction = getTransaction(db, objectStoreNames, "readwrite", 45 var transaction = getTransaction(db, objectStoreNames, "readwrite",
62 function() { onSetupComplete(db); }); 46 function() { onSetupComplete(db); });
63 var os = transaction.objectStore(storeName); 47 putLinearValues(transaction, objectStoreNames, numKeys,
64 assert(os); 48 function () { return "test value"; });
jsbell 2012/07/26 18:52:41 Isn't this being specified for the getKey argument
ericu 2012/07/26 21:03:13 Yup; fixed.
65 for (var j = 0; j < numKeys; ++j) {
66 os.put(getValue(i), getKey(j));
67 }
68 } 49 }
69 var cleanUpFunc; 50 var cleanUpFunc;
70 function onSetupComplete(db) { 51 function onSetupComplete(db) {
71 automation.setStatus("Setup complete."); 52 automation.setStatus("Setup complete.");
72 runOneBatch(db); 53 runOneBatch(db);
73 cleanUpFunc = getCleanUpFunc(testName, Date.now(), onTestComplete); 54 cleanUpFunc = getCleanUpFunc(testName, Date.now(), onTestComplete);
74 } 55 }
75 56
76 function runOneBatch(db) { 57 function runOneBatch(db) {
77 if (numTransactionsLeft <= 0) { 58 if (numTransactionsLeft <= 0) {
78 return; 59 return;
79 } 60 }
80 --numTransactionsLeft; 61 --numTransactionsLeft;
81 ++numTransactionsRunning; 62 ++numTransactionsRunning;
82 var valuesToRead = numReadsPerTransaction; 63 var mode = "readonly";
83 var transaction = getTransaction(db, objectStoreNames, "readonly", 64 if (numWritesPerTransaction)
65 mode = "readwrite";
66 var transaction = getTransaction(db, objectStoreNames, mode,
84 function() { 67 function() {
85 assert(!--numTransactionsRunning); 68 assert(!--numTransactionsRunning);
86 assert(!valuesToRead);
87 if (numTransactionsLeft <= 0) { 69 if (numTransactionsLeft <= 0) {
88 cleanUpFunc(); 70 cleanUpFunc();
89 } else { 71 } else {
90 runOneBatch(db); 72 runOneBatch(db);
91 } 73 }
92 }); 74 });
93 75
94 var queryObject = transaction.objectStore(storeName); 76 getRandomValues(transaction, objectStoreNames, numReadsPerTransaction,
95 if (useIndex) { 77 numKeys, indexName);
96 queryObject = queryObject.index(indexName); 78 putRandomValues(transaction, objectStoreNames, numWritesPerTransaction,
97 } 79 numKeys);
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 } 80 }
108 81
109 automation.setStatus("Creating database."); 82 automation.setStatus("Creating database.");
110 var options = {}; 83 var options = {};
111 if (useIndex) { 84 if (useIndexForReads) {
112 options.indexName = indexName; 85 options.indexName = indexName;
113 options.indexKeyPath = ""; 86 options.indexKeyPath = "";
114 options.indexIsUnique = true; 87 options.indexIsUnique = true;
115 options.indexIsMultiEntry = false; 88 options.indexIsMultiEntry = false;
116 } 89 }
117 createDatabase(testName, objectStoreNames, onCreated, onError, options); 90 createDatabase(testName, objectStoreNames, onCreated, onError, options);
118 } 91 }
119 92
93 function testCreateAndDeleteIndex(numKeys, onTestComplete) {
94 var testName = getDisplayName(arguments);
95 var objectStoreNames = ["store"];
96 function getValue(i) {
97 return { firstName: i + " first name", lastName: i + " last name" };
98 }
99
100 var startTime;
101 function onCreated(db) {
102 automation.setStatus("Initializing data.");
103 var transaction = getTransaction(db, objectStoreNames, "readwrite",
104 function() { onPopulated(db); });
105 putLinearValues(transaction, objectStoreNames, numKeys, null, getValue);
106 }
107
108 function onPopulated(db) {
109 db.close();
110 automation.setStatus("Building index.");
111 startTime = Date.now();
112 var f =
113 function(objectStore) {
114 objectStore.createIndex("index", "firstName", {unique: true});
115 }
jsbell 2012/07/26 18:52:41 Missing semicolon.
ericu 2012/07/26 21:03:13 Done.
116 alterObjectStores(testName, objectStoreNames, f, onIndexCreated, onError);
117 }
118
119 var cleanUpFunc;
120 function onIndexCreated(db) {
121 db.close();
122 var indexCreationCompleteTime = Date.now();
123 automation.addResult("testCreateIndex",
124 indexCreationCompleteTime - startTime);
125 cleanUpFunc = getCleanUpFunc("testDeleteIndex",
126 indexCreationCompleteTime, onTestComplete);
127 var f =
128 function(objectStore) {
129 objectStore.deleteIndex("index");
130 }
jsbell 2012/07/26 18:52:41 Missing semicolon.
ericu 2012/07/26 21:03:13 Done.
131 automation.setStatus("Deleting index.");
132 alterObjectStores(testName, objectStoreNames, f, cleanUpFunc, onError);
133 }
134
135 function onIndexDeleted(db) {
jsbell 2012/07/26 18:52:41 Not used?
ericu 2012/07/26 21:03:13 Removed.
136 cleanUpFunc(db);
jsbell 2012/07/26 18:52:41 The function returned by getCleanUpFunc() doesn't
ericu 2012/07/26 21:03:13 Done.
137 }
138
139 automation.setStatus("Creating database.");
140 createDatabase(testName, objectStoreNames, onCreated, onError);
141 }
142
120 var tests = [ 143 var tests = [
121 [testCreateKeysInStores, 1, 1, 1], 144 [testCreateKeysInStores, 1, 1, 1],
122 [testCreateKeysInStores, 100, 1, 1], 145 [testCreateKeysInStores, 100, 1, 1],
123 [testCreateKeysInStores, 1, 100, 1], 146 [testCreateKeysInStores, 1, 100, 1],
124 [testCreateKeysInStores, 100, 1, 10000], 147 [testCreateKeysInStores, 100, 1, 10000],
125 [testRandomReads, 1000, 5, 50, false], 148 [testRandomReadsAndWrites, 1000, 5, 0, 50, false],
126 [testRandomReads, 1000, 50, 5, false], 149 [testRandomReadsAndWrites, 1000, 50, 0, 5, false],
127 [testRandomReads, 5000, 50, 5, false], 150 [testRandomReadsAndWrites, 5000, 50, 0, 5, false],
128 [testRandomReads, 1000, 5, 50, true], 151 [testRandomReadsAndWrites, 1000, 5, 0, 50, true],
129 [testRandomReads, 1000, 50, 5, true], 152 [testRandomReadsAndWrites, 1000, 50, 0, 5, true],
130 [testRandomReads, 5000, 50, 5, true] 153 [testRandomReadsAndWrites, 5000, 50, 0, 5, true],
154 [testRandomReadsAndWrites, 1000, 5, 5, 50, false],
155 [testRandomReadsAndWrites, 1000, 5, 5, 50, true],
156 [testCreateAndDeleteIndex, 1000]
131 ]; 157 ];
132 158
133 var currentTest = 0; 159 var currentTest = 0;
134 160
135 function runNextTest() { 161 function runNextTest() {
136 if (currentTest < tests.length) { 162 if (currentTest < tests.length) {
137 var test = tests[currentTest++].slice(); 163 var test = tests[currentTest++].slice();
138 var f = test.shift(); 164 var f = test.shift();
139 test.push(runNextTest); 165 test.push(runNextTest);
140 f.apply(null, test); 166 f.apply(null, test);
141 } else { 167 } else {
142 onAllTestsComplete(); 168 onAllTestsComplete();
143 } 169 }
144 } 170 }
145 171
146 function onAllTestsComplete() { 172 function onAllTestsComplete() {
147 var overallDuration = Date.now() - overallTestStartTime; 173 var overallDuration = Date.now() - overallTestStartTime;
148 automation.addResult("OverallTestDuration", overallDuration); 174 automation.addResult("OverallTestDuration", overallDuration);
149 automation.setDone(); 175 automation.setDone();
150 } 176 }
151 177
152 function test() { 178 function test() {
153 runNextTest(); 179 runNextTest();
154 } 180 }
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