Chromium Code Reviews| Index: chrome/test/data/indexeddb/perf_test.js |
| diff --git a/chrome/test/data/indexeddb/perf_test.js b/chrome/test/data/indexeddb/perf_test.js |
| index 332b94397880cbc601459cf621bde11686fbbb4b..89e409a8dc291b87d5a5dd5f2397de8915c2e249 100644 |
| --- a/chrome/test/data/indexeddb/perf_test.js |
| +++ b/chrome/test/data/indexeddb/perf_test.js |
| @@ -6,8 +6,7 @@ var overallTestStartTime = Date.now(); |
| function testCreateKeysInStores( |
| numKeys, numStores, payloadLength, onTestComplete) { |
| - var testName = "testCreateKeysInStores_" + numKeys + "_" + numStores + "_" + |
| - payloadLength; |
| + var testName = getDisplayName(arguments); |
| assert(numKeys >= 0); |
| assert(numStores >= 1); |
| var objectStoreNames = []; |
| @@ -15,56 +14,38 @@ function testCreateKeysInStores( |
| objectStoreNames.push("store " + i); |
| } |
| var value = stringOfLength(payloadLength); |
| + function getValue() { |
| + return value; |
| + } |
| function onCreated(db) { |
| automation.setStatus("Constructing transaction."); |
| var cleanUpFunc = getCleanUpFunc(testName, Date.now(), onTestComplete); |
| var transaction = getTransaction(db, objectStoreNames, "readwrite", |
| function() { cleanUpFunc(); }); |
| - for (var i in objectStoreNames) { |
| - var os = transaction.objectStore(objectStoreNames[i]); |
| - assert(os); |
| - for (var j = 0; j < numKeys; ++j) { |
| - os.put(value, "key " + j); |
| - } |
| - } |
| + putLinearValues(transaction, objectStoreNames, numKeys, null, getValue); |
| } |
| automation.setStatus("Creating database."); |
| createDatabase(testName, objectStoreNames, onCreated, onError); |
| } |
| -function testRandomReads(numKeys, numReadsPerTransaction, numTransactions, |
| - useIndex, onTestComplete) { |
| - var indexText = "_bare"; |
| +function testRandomReadsAndWrites( |
| + numKeys, numReadsPerTransaction, numWritesPerTransaction, numTransactions, |
| + useIndexForReads, onTestComplete) { |
| var indexName; |
| - if (useIndex) { |
| - indexText = "_index"; |
| + if (useIndexForReads) |
| indexName = "index"; |
| - } |
| - var testName = "testRandomReads_" + numKeys + "_" + numReadsPerTransaction + |
| - "_" + numTransactions + indexText; |
| + var testName = getDisplayName(arguments); |
| var numTransactionsLeft = numTransactions; |
| - var storeName = "store"; |
| - var objectStoreNames = [storeName]; |
| + var objectStoreNames = ["store"]; |
| var numTransactionsRunning; |
| - function getKey(i) { |
| - return "key " + i; |
| - } |
| - |
| - function getValue(i) { |
| - return "value " + i; |
| - } |
| - |
| function onCreated(db) { |
| automation.setStatus("Setting up test database."); |
| var transaction = getTransaction(db, objectStoreNames, "readwrite", |
| function() { onSetupComplete(db); }); |
| - var os = transaction.objectStore(storeName); |
| - assert(os); |
| - for (var j = 0; j < numKeys; ++j) { |
| - os.put(getValue(i), getKey(j)); |
| - } |
| + putLinearValues(transaction, objectStoreNames, numKeys, |
| + 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.
|
| } |
| var cleanUpFunc; |
| function onSetupComplete(db) { |
| @@ -79,11 +60,12 @@ function testRandomReads(numKeys, numReadsPerTransaction, numTransactions, |
| } |
| --numTransactionsLeft; |
| ++numTransactionsRunning; |
| - var valuesToRead = numReadsPerTransaction; |
| - var transaction = getTransaction(db, objectStoreNames, "readonly", |
| + var mode = "readonly"; |
| + if (numWritesPerTransaction) |
| + mode = "readwrite"; |
| + var transaction = getTransaction(db, objectStoreNames, mode, |
| function() { |
| assert(!--numTransactionsRunning); |
| - assert(!valuesToRead); |
| if (numTransactionsLeft <= 0) { |
| cleanUpFunc(); |
| } else { |
| @@ -91,24 +73,15 @@ function testRandomReads(numKeys, numReadsPerTransaction, numTransactions, |
| } |
| }); |
| - var queryObject = transaction.objectStore(storeName); |
| - if (useIndex) { |
| - queryObject = queryObject.index(indexName); |
| - } |
| - assert(queryObject); |
| - for (var i = 0; i < numReadsPerTransaction; ++i) { |
| - var rand = Math.floor(Math.random() * numKeys); |
| - var request = queryObject.get(getKey(rand)); |
| - request.onerror = onError; |
| - request.onsuccess = function () { |
| - assert(valuesToRead--); |
| - } |
| - } |
| + getRandomValues(transaction, objectStoreNames, numReadsPerTransaction, |
| + numKeys, indexName); |
| + putRandomValues(transaction, objectStoreNames, numWritesPerTransaction, |
| + numKeys); |
| } |
| automation.setStatus("Creating database."); |
| var options = {}; |
| - if (useIndex) { |
| + if (useIndexForReads) { |
| options.indexName = indexName; |
| options.indexKeyPath = ""; |
| options.indexIsUnique = true; |
| @@ -117,17 +90,70 @@ function testRandomReads(numKeys, numReadsPerTransaction, numTransactions, |
| createDatabase(testName, objectStoreNames, onCreated, onError, options); |
| } |
| +function testCreateAndDeleteIndex(numKeys, onTestComplete) { |
| + var testName = getDisplayName(arguments); |
| + var objectStoreNames = ["store"]; |
| + function getValue(i) { |
| + return { firstName: i + " first name", lastName: i + " last name" }; |
| + } |
| + |
| + var startTime; |
| + function onCreated(db) { |
| + automation.setStatus("Initializing data."); |
| + var transaction = getTransaction(db, objectStoreNames, "readwrite", |
| + function() { onPopulated(db); }); |
| + putLinearValues(transaction, objectStoreNames, numKeys, null, getValue); |
| + } |
| + |
| + function onPopulated(db) { |
| + db.close(); |
| + automation.setStatus("Building index."); |
| + startTime = Date.now(); |
| + var f = |
| + function(objectStore) { |
| + objectStore.createIndex("index", "firstName", {unique: true}); |
| + } |
|
jsbell
2012/07/26 18:52:41
Missing semicolon.
ericu
2012/07/26 21:03:13
Done.
|
| + alterObjectStores(testName, objectStoreNames, f, onIndexCreated, onError); |
| + } |
| + |
| + var cleanUpFunc; |
| + function onIndexCreated(db) { |
| + db.close(); |
| + var indexCreationCompleteTime = Date.now(); |
| + automation.addResult("testCreateIndex", |
| + indexCreationCompleteTime - startTime); |
| + cleanUpFunc = getCleanUpFunc("testDeleteIndex", |
| + indexCreationCompleteTime, onTestComplete); |
| + var f = |
| + function(objectStore) { |
| + objectStore.deleteIndex("index"); |
| + } |
|
jsbell
2012/07/26 18:52:41
Missing semicolon.
ericu
2012/07/26 21:03:13
Done.
|
| + automation.setStatus("Deleting index."); |
| + alterObjectStores(testName, objectStoreNames, f, cleanUpFunc, onError); |
| + } |
| + |
| + function onIndexDeleted(db) { |
|
jsbell
2012/07/26 18:52:41
Not used?
ericu
2012/07/26 21:03:13
Removed.
|
| + cleanUpFunc(db); |
|
jsbell
2012/07/26 18:52:41
The function returned by getCleanUpFunc() doesn't
ericu
2012/07/26 21:03:13
Done.
|
| + } |
| + |
| + automation.setStatus("Creating database."); |
| + createDatabase(testName, objectStoreNames, onCreated, onError); |
| +} |
| + |
| var tests = [ |
| [testCreateKeysInStores, 1, 1, 1], |
| [testCreateKeysInStores, 100, 1, 1], |
| [testCreateKeysInStores, 1, 100, 1], |
| [testCreateKeysInStores, 100, 1, 10000], |
| - [testRandomReads, 1000, 5, 50, false], |
| - [testRandomReads, 1000, 50, 5, false], |
| - [testRandomReads, 5000, 50, 5, false], |
| - [testRandomReads, 1000, 5, 50, true], |
| - [testRandomReads, 1000, 50, 5, true], |
| - [testRandomReads, 5000, 50, 5, true] |
| + [testRandomReadsAndWrites, 1000, 5, 0, 50, false], |
| + [testRandomReadsAndWrites, 1000, 50, 0, 5, false], |
| + [testRandomReadsAndWrites, 5000, 50, 0, 5, false], |
| + [testRandomReadsAndWrites, 1000, 5, 0, 50, true], |
| + [testRandomReadsAndWrites, 1000, 50, 0, 5, true], |
| + [testRandomReadsAndWrites, 5000, 50, 0, 5, true], |
| + [testRandomReadsAndWrites, 1000, 5, 5, 50, false], |
| + [testRandomReadsAndWrites, 1000, 5, 5, 50, true], |
| + [testCreateAndDeleteIndex, 1000] |
| ]; |
| var currentTest = 0; |