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

Unified 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, 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 9e3bbab38da5f4d22ff10ddc776f0fb018953e9a..332b94397880cbc601459cf621bde11686fbbb4b 100644
--- a/chrome/test/data/indexeddb/perf_test.js
+++ b/chrome/test/data/indexeddb/perf_test.js
@@ -15,41 +15,119 @@ function testCreateKeysInStores(
objectStoreNames.push("store " + i);
}
var value = stringOfLength(payloadLength);
- var start;
function onCreated(db) {
automation.setStatus("Constructing transaction.");
- start = Date.now(); // Ignore the setup time for this test.
+ 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
var transaction = getTransaction(db, objectStoreNames, "readwrite",
- function() { onTransactionComplete(db); });
+ function() { cleanUpFunc(); });
for (var i in objectStoreNames) {
var os = transaction.objectStore(objectStoreNames[i]);
assert(os);
for (var j = 0; j < numKeys; ++j) {
- os.put("key " + j, value);
+ os.put(value, "key " + j);
}
}
}
- function onTransactionComplete(db) {
- var duration = Date.now() - start;
- // Ignore the cleanup time for this test.
- automation.addResult(testName, duration);
- automation.setStatus("Deleting.");
- deleteDatabase(db, onDeleted);
+ automation.setStatus("Creating database.");
+ createDatabase(testName, objectStoreNames, onCreated, onError);
+}
+
+function testRandomReads(numKeys, numReadsPerTransaction, numTransactions,
+ useIndex, onTestComplete) {
+ var indexText = "_bare";
+ var indexName;
+ if (useIndex) {
+ indexText = "_index";
+ indexName = "index";
}
- function onDeleted() {
- automation.setStatus("Deleted.");
- onTestComplete();
+ var testName = "testRandomReads_" + numKeys + "_" + numReadsPerTransaction +
+ "_" + numTransactions + indexText;
+ var numTransactionsLeft = numTransactions;
+ var storeName = "store";
+ 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
+ var numTransactionsRunning;
+
+ function getKey(i) {
+ return "key " + i;
}
- automation.setStatus("Creating.");
- createDatabase(testName, objectStoreNames, onCreated, onError);
+
+ 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));
+ }
+ }
+ var cleanUpFunc;
+ function onSetupComplete(db) {
+ automation.setStatus("Setup complete.");
+ runOneBatch(db);
+ cleanUpFunc = getCleanUpFunc(testName, Date.now(), onTestComplete);
+ }
+
+ function runOneBatch(db) {
+ if (numTransactionsLeft <= 0) {
+ return;
+ }
+ --numTransactionsLeft;
+ ++numTransactionsRunning;
+ var valuesToRead = numReadsPerTransaction;
+ var transaction = getTransaction(db, objectStoreNames, "readonly",
+ function() {
+ assert(!--numTransactionsRunning);
+ assert(!valuesToRead);
+ if (numTransactionsLeft <= 0) {
+ cleanUpFunc();
+ } else {
+ runOneBatch(db);
+ }
+ });
+
+ 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--);
+ }
+ }
+ }
+
+ automation.setStatus("Creating database.");
+ var options = {};
+ if (useIndex) {
+ options.indexName = indexName;
+ options.indexKeyPath = "";
+ options.indexIsUnique = true;
+ options.indexIsMultiEntry = false;
+ }
+ 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
}
var tests = [
- [testCreateKeysInStores, 1, 1, 1],
- [testCreateKeysInStores, 100, 1, 1],
- [testCreateKeysInStores, 1, 100, 1],
- [testCreateKeysInStores, 100, 1, 100000]
+ [testCreateKeysInStores, 1, 1, 1],
+ [testCreateKeysInStores, 100, 1, 1],
+ [testCreateKeysInStores, 1, 100, 1],
+ [testCreateKeysInStores, 100, 1, 10000],
+ [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.
+ [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]
];
var currentTest = 0;
« 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