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

Unified Diff: chrome/test/data/indexeddb/perf_test.js

Issue 10826038: Add more IDB perf tests, including cursor reads and log-style writes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tiny tweaks Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
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 6e797f187b59c199519866f3e90b9df8e7965b3f..2eaf456353c4d8518de733395647778fb88477a9 100644
--- a/chrome/test/data/indexeddb/perf_test.js
+++ b/chrome/test/data/indexeddb/perf_test.js
@@ -51,8 +51,8 @@ function testRandomReadsAndWrites(
var completionFunc;
function onSetupComplete(db) {
automation.setStatus("Setup complete.");
- runOneBatch(db);
completionFunc = getCompletionFunc(testName, Date.now(), onTestComplete);
+ runOneBatch(db);
}
function runOneBatch(db) {
@@ -81,12 +81,14 @@ function testRandomReadsAndWrites(
}
automation.setStatus("Creating database.");
- var options = {};
+ var options;
if (useIndexForReads) {
- options.indexName = indexName;
- options.indexKeyPath = "";
- options.indexIsUnique = false;
- options.indexIsMultiEntry = false;
+ options = [{
+ indexName: indexName,
+ indexKeyPath: "",
+ indexIsUnique: false,
+ indexIsMultiEntry: false,
+ }];
}
createDatabase(testName, objectStoreNames, onCreated, onError, options);
}
@@ -135,21 +137,190 @@ function testCreateAndDeleteIndex(numKeys, onTestComplete) {
createDatabase(testName, objectStoreNames, onCreated, onError);
}
+function testCursorReadsAndRandomWrites(
+ readKeysOnly, useIndexForReads, writeToAnotherStore, onTestComplete) {
+ // There's no key cursor unless you're reading from an index.
+ assert(useIndexForReads || !readKeysOnly);
+ // If we're writing to another store, having an index would constrain our
+ // writes, as we create both object stores with the same configurations.
+ // We could do that if needed, but it's simpler not to.
+ assert(!useIndexForReads || !writeToAnotherStore);
+ var numKeys = 1000;
+ var numReadsPerTransaction = 100;
+ var testName = getDisplayName(arguments);
+ var objectStoreNames = ["input store"];
+ if (writeToAnotherStore)
+ objectStoreNames.push("output store");
+ var getKeyForRead = getSimpleKey;
+ var indexName;
+ if (useIndexForReads) {
+ indexName = "index";
+ getKeyForRead = function(i) {
+ // This depends on the implementations of getValuesFromCursor and
+ // getObjectValue. We reverse the order of the iteration here so that
+ // setting up bounds from k to k+n with n>0 works. Without this reversal,
+ // the upper bound is below the lower bound.
+ return getBackwardIndexKey(numKeys - i);
+ }
+ }
+
+ function onCreated(db) {
+ automation.setStatus("Setting up test database.");
+ var transaction = getTransaction(db, objectStoreNames, "readwrite",
+ function() { onSetupComplete(db); });
+ putLinearValues(transaction, objectStoreNames, numKeys, getSimpleKey,
+ getObjectValue);
+ }
+ function onSetupComplete(db) {
+ automation.setStatus("Setup complete.");
+ var completionFunc =
+ getCompletionFunc(testName, Date.now(), onTestComplete);
+ var mode = "readonly";
+ if (writeToAnotherStore)
+ mode = "readwrite";
+ var transaction =
+ getTransaction(db, objectStoreNames, mode, completionFunc);
+
+ getValuesFromCursor(
+ transaction, objectStoreNames[0], numReadsPerTransaction, numKeys,
+ indexName, getKeyForRead, readKeysOnly, objectStoreNames[1]);
+ }
+
+ automation.setStatus("Creating database.");
+ var options;
+ if (useIndexForReads) {
+ options = [{
+ indexName: indexName,
+ indexKeyPath: "lastName", // depends on getBackwardIndexKey()
+ indexIsUnique: true,
+ indexIsMultiEntry: false,
+ }];
+ }
+ createDatabase(testName, objectStoreNames, onCreated, onError, options);
+}
+
+function testSporadicWrites(
+ numWritesPerTransaction, numIndices, onTestComplete) {
+ var numKeys = 1000;
+ // With 30 transactions, spaced 50ms apart, we'll need at least 1.5s.
+ var numTransactions = 30;
+ var delayBetweenBatches = 50;
+ var indexName;
+ var testName = getDisplayName(arguments);
+ var numTransactionsLeft = numTransactions;
+ var objectStoreNames = ["store"];
+ var numTransactionsRunning = 0;
+
+ var getValue = getSimpleValue;
+ if (numIndices)
+ getValue = function (i) { return getNFieldObjectValue(i, numIndices); };
+
+ function onCreated(db) {
+ automation.setStatus("Setting up test database.");
+ var transaction = getTransaction(db, objectStoreNames, "readwrite",
+ function() { onSetupComplete(db); });
+ putLinearValues(transaction, objectStoreNames, numKeys, getSimpleKey,
+ getValue);
+ }
+ var completionFunc;
+ function onSetupComplete(db) {
+ automation.setStatus("Setup complete.");
+ completionFunc = getCompletionFunc(testName, Date.now(), onTestComplete);
+ runOneBatch(db);
+ }
+
+ function runOneBatch(db) {
+ assert(numTransactionsLeft);
+ if (--numTransactionsLeft) {
+ setTimeout(function () { runOneBatch(db); }, delayBetweenBatches);
+ }
+ ++numTransactionsRunning;
+
+ function batchComplete() {
+ assert(numTransactionsRunning);
+ if (!--numTransactionsRunning && !numTransactionsLeft)
+ completionFunc();
+ }
+
+ var mode = "readonly";
+ if (numWritesPerTransaction)
+ mode = "readwrite";
+
+ var transaction = getTransaction(db, objectStoreNames, mode, batchComplete);
+ putRandomValues(transaction, objectStoreNames, numWritesPerTransaction,
+ numKeys);
+ }
+
+ automation.setStatus("Creating database.");
+ var options = [];
+ for (var i=0; i < numIndices; ++i) {
+ var o = {};
+ o.indexName = "index " + i;
+ o.indexKeyPath = "field" + i; // depends on getNFieldObjectValue
jsbell 2012/07/27 00:25:46 Maybe add function getNFieldName(n) { return "fiel
ericu 2012/07/31 01:00:53 Done.
+ o.indexIsUnique = false;
+ o.indexIsMultiEntry = false;
+ options.push(o);
+ }
+ createDatabase(testName, objectStoreNames, onCreated, onError, options);
+}
+
var kUseIndex = true;
var kDontUseIndex = false;
+var kReadKeysOnly = true;
+var kReadDataToo = false;
+var kWriteToo = true;
+var kDontWrite = false;
+
var tests = [
+// Create a single small item in a single object store.
[testCreateKeysInStores, 1, 1, 1],
+// Create many small items in a single object store.
[testCreateKeysInStores, 100, 1, 1],
+// Create a single small item in many object stores.
[testCreateKeysInStores, 1, 100, 1],
+// Create many large items in a single object store.
[testCreateKeysInStores, 100, 1, 10000],
+// Read a few random items in each of many transactions.
[testRandomReadsAndWrites, 1000, 5, 0, 50, kDontUseIndex],
+// Read many random items in each of a few transactions.
[testRandomReadsAndWrites, 1000, 50, 0, 5, kDontUseIndex],
+// Read many random items in each of a few transactions, in a large store.
[testRandomReadsAndWrites, 5000, 50, 0, 5, kDontUseIndex],
+// Read a few random items from an index, in each of many transactions.
[testRandomReadsAndWrites, 1000, 5, 0, 50, kUseIndex],
+// Read many random items from an index, in each of a few transactions.
[testRandomReadsAndWrites, 1000, 50, 0, 5, kUseIndex],
+// Read many random items from an index, in each of a few transactions, in a
+// large store.
[testRandomReadsAndWrites, 5000, 50, 0, 5, kUseIndex],
+// Read and write a few random items in each of many transactions.
[testRandomReadsAndWrites, 1000, 5, 5, 50, kDontUseIndex],
+// Read and write a few random items, reading from an index, in each of many
+// transactions.
[testRandomReadsAndWrites, 1000, 5, 5, 50, kUseIndex],
+// Read a long, contiguous sequence of an object store via a cursor.
+ [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kDontWrite],
+// Read a sequence of an object store via a cursor, writing
+// transformed values into another.
+ [testCursorReadsAndRandomWrites, kReadDataToo, kDontUseIndex, kWriteToo],
+// Read a sequence of an index into an object store via a cursor.
+ [testCursorReadsAndRandomWrites, kReadDataToo, kUseIndex, kDontWrite],
+// Read a sequence of an index into an object store via a key cursor.
+ [testCursorReadsAndRandomWrites, kReadKeysOnly, kUseIndex, kDontWrite],
+// Make batches of random writes into a store, triggered by periodic setTimeout
+// calls.
+ [testSporadicWrites, 5, 0],
+// Make large batches of random writes into a store, triggered by periodic
+// setTimeout calls.
+ [testSporadicWrites, 50, 0],
+// Make batches of random writes into a store with many indices, triggered by
+// periodic setTimeout calls.
+ [testSporadicWrites, 5, 10],
+// Make large batches of random writes into a store with many indices, triggered
+// by periodic setTimeout calls.
+ [testSporadicWrites, 50, 10],
+// Create and delete an index on a store that already contains data [produces
+// a timing result for each of creation and deletion].
[testCreateAndDeleteIndex, 1000]
];
« 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