| 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..49a257fa90520b74ca49a827ca206e83a8e05e2d 100644
|
| --- a/chrome/test/data/indexeddb/perf_test.js
|
| +++ b/chrome/test/data/indexeddb/perf_test.js
|
| @@ -15,41 +15,123 @@ 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 completionFunc =
|
| + getCompletionFunc(testName, Date.now(), onTestComplete);
|
| var transaction = getTransaction(db, objectStoreNames, "readwrite",
|
| - function() { onTransactionComplete(db); });
|
| + function() { completionFunc(); });
|
| 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];
|
| + 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 completionFunc;
|
| + function onSetupComplete(db) {
|
| + automation.setStatus("Setup complete.");
|
| + runOneBatch(db);
|
| + completionFunc = getCompletionFunc(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) {
|
| + completionFunc();
|
| + } 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);
|
| }
|
|
|
| +var kUseIndex = true;
|
| +var kDontUseIndex = false;
|
| +
|
| 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, kDontUseIndex],
|
| + [testRandomReads, 1000, 50, 5, kDontUseIndex],
|
| + [testRandomReads, 5000, 50, 5, kDontUseIndex],
|
| + [testRandomReads, 1000, 5, 50, kUseIndex],
|
| + [testRandomReads, 1000, 50, 5, kUseIndex],
|
| + [testRandomReads, 5000, 50, 5, kUseIndex]
|
| ];
|
|
|
| var currentTest = 0;
|
|
|