Commit f67ca023 authored by ericu@google.com's avatar ericu@google.com

Reorder declaration vs. usage, build padToWidth on top of stringOfLength.

All changes in perf_test.js are reorders--no actual code change.

BUG=137764
TEST=self

Review URL: https://chromiumcodereview.appspot.com/10828119

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149477 0039d316-1c4b-4281-b951-d872f2087c98
parent f50d3466
...@@ -193,12 +193,20 @@ function getDisplayName(args) { ...@@ -193,12 +193,20 @@ function getDisplayName(args) {
function padToWidth(s, width) { function padToWidth(s, width) {
s = String(s); s = String(s);
assert(s.length <= width); assert(s.length <= width);
while (s.length < width) { if (s.length < width) {
s = "0" + s; s = stringOfLength(width - s.length, '0') + s;
} }
return s; return s;
} }
function stringOfLength(n, c) {
if (c == null)
c = 'X';
assert(n > 0);
assert(n == Math.floor(n));
return new Array(n + 1).join(c);
}
function getSimpleKey(i) { function getSimpleKey(i) {
return "key " + padToWidth(i, 10); return "key " + padToWidth(i, 10);
} }
...@@ -334,10 +342,3 @@ function getValuesFromCursor( ...@@ -334,10 +342,3 @@ function getValuesFromCursor(
} }
request.onerror = onError; request.onerror = onError;
} }
function stringOfLength(n) {
assert(n > 0);
assert(n == Math.floor(n));
return new Array(n + 1).join('0');
}
...@@ -3,6 +3,88 @@ ...@@ -3,6 +3,88 @@
// found in the LICENSE file. // found in the LICENSE file.
var overallTestStartTime = Date.now(); var overallTestStartTime = Date.now();
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]
];
var currentTest = 0;
function test() {
runNextTest();
}
function runNextTest() {
if (currentTest < tests.length) {
var test = tests[currentTest++].slice();
var f = test.shift();
test.push(runNextTest);
f.apply(null, test);
} else {
onAllTestsComplete();
}
}
function onAllTestsComplete() {
var overallDuration = Date.now() - overallTestStartTime;
automation.addResult("OverallTestDuration", overallDuration);
automation.setDone();
}
function testCreateKeysInStores( function testCreateKeysInStores(
numKeys, numStores, payloadLength, onTestComplete) { numKeys, numStores, payloadLength, onTestComplete) {
...@@ -18,6 +100,9 @@ function testCreateKeysInStores( ...@@ -18,6 +100,9 @@ function testCreateKeysInStores(
return value; return value;
} }
automation.setStatus("Creating database.");
createDatabase(testName, objectStoreNames, onCreated, onError);
function onCreated(db) { function onCreated(db) {
automation.setStatus("Constructing transaction."); automation.setStatus("Constructing transaction.");
var completionFunc = var completionFunc =
...@@ -26,8 +111,6 @@ function testCreateKeysInStores( ...@@ -26,8 +111,6 @@ function testCreateKeysInStores(
getTransaction(db, objectStoreNames, "readwrite", completionFunc); getTransaction(db, objectStoreNames, "readwrite", completionFunc);
putLinearValues(transaction, objectStoreNames, numKeys, null, getValue); putLinearValues(transaction, objectStoreNames, numKeys, null, getValue);
} }
automation.setStatus("Creating database.");
createDatabase(testName, objectStoreNames, onCreated, onError);
} }
function testRandomReadsAndWrites( function testRandomReadsAndWrites(
...@@ -41,6 +124,18 @@ function testRandomReadsAndWrites( ...@@ -41,6 +124,18 @@ function testRandomReadsAndWrites(
var objectStoreNames = ["store"]; var objectStoreNames = ["store"];
var numTransactionsRunning; var numTransactionsRunning;
automation.setStatus("Creating database.");
var options;
if (useIndexForReads) {
options = [{
indexName: indexName,
indexKeyPath: "",
indexIsUnique: false,
indexIsMultiEntry: false,
}];
}
createDatabase(testName, objectStoreNames, onCreated, onError, options);
function onCreated(db) { function onCreated(db) {
automation.setStatus("Setting up test database."); automation.setStatus("Setting up test database.");
var transaction = getTransaction(db, objectStoreNames, "readwrite", var transaction = getTransaction(db, objectStoreNames, "readwrite",
...@@ -48,6 +143,7 @@ function testRandomReadsAndWrites( ...@@ -48,6 +143,7 @@ function testRandomReadsAndWrites(
putLinearValues(transaction, objectStoreNames, numKeys, null, putLinearValues(transaction, objectStoreNames, numKeys, null,
function () { return "test value"; }); function () { return "test value"; });
} }
var completionFunc; var completionFunc;
function onSetupComplete(db) { function onSetupComplete(db) {
automation.setStatus("Setup complete."); automation.setStatus("Setup complete.");
...@@ -79,26 +175,14 @@ function testRandomReadsAndWrites( ...@@ -79,26 +175,14 @@ function testRandomReadsAndWrites(
putRandomValues(transaction, objectStoreNames, numWritesPerTransaction, putRandomValues(transaction, objectStoreNames, numWritesPerTransaction,
numKeys); numKeys);
} }
automation.setStatus("Creating database.");
var options;
if (useIndexForReads) {
options = [{
indexName: indexName,
indexKeyPath: "",
indexIsUnique: false,
indexIsMultiEntry: false,
}];
}
createDatabase(testName, objectStoreNames, onCreated, onError, options);
} }
function testCreateAndDeleteIndex(numKeys, onTestComplete) { function testCreateAndDeleteIndex(numKeys, onTestComplete) {
var testName = getDisplayName(arguments); var testName = getDisplayName(arguments);
var objectStoreNames = ["store"]; var objectStoreNames = ["store"];
function getValue(i) {
return { firstName: i + " first name", lastName: i + " last name" }; automation.setStatus("Creating database.");
} createDatabase(testName, objectStoreNames, onCreated, onError);
var startTime; var startTime;
function onCreated(db) { function onCreated(db) {
...@@ -108,6 +192,10 @@ function testCreateAndDeleteIndex(numKeys, onTestComplete) { ...@@ -108,6 +192,10 @@ function testCreateAndDeleteIndex(numKeys, onTestComplete) {
putLinearValues(transaction, objectStoreNames, numKeys, null, getValue); putLinearValues(transaction, objectStoreNames, numKeys, null, getValue);
} }
function getValue(i) {
return { firstName: i + " first name", lastName: i + " last name" };
}
function onPopulated(db) { function onPopulated(db) {
db.close(); db.close();
automation.setStatus("Building index."); automation.setStatus("Building index.");
...@@ -132,9 +220,6 @@ function testCreateAndDeleteIndex(numKeys, onTestComplete) { ...@@ -132,9 +220,6 @@ function testCreateAndDeleteIndex(numKeys, onTestComplete) {
automation.setStatus("Deleting index."); automation.setStatus("Deleting index.");
alterObjectStores(testName, objectStoreNames, f, completionFunc, onError); alterObjectStores(testName, objectStoreNames, f, completionFunc, onError);
} }
automation.setStatus("Creating database.");
createDatabase(testName, objectStoreNames, onCreated, onError);
} }
// TODO: Add a version that writes back to the same store, to see how that // TODO: Add a version that writes back to the same store, to see how that
...@@ -166,6 +251,18 @@ function testCursorReadsAndRandomWrites( ...@@ -166,6 +251,18 @@ function testCursorReadsAndRandomWrites(
} }
} }
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 onCreated(db) { function onCreated(db) {
automation.setStatus("Setting up test database."); automation.setStatus("Setting up test database.");
var transaction = getTransaction(db, objectStoreNames, "readwrite", var transaction = getTransaction(db, objectStoreNames, "readwrite",
...@@ -187,18 +284,6 @@ function testCursorReadsAndRandomWrites( ...@@ -187,18 +284,6 @@ function testCursorReadsAndRandomWrites(
transaction, objectStoreNames[0], numReadsPerTransaction, numKeys, transaction, objectStoreNames[0], numReadsPerTransaction, numKeys,
indexName, getKeyForRead, readKeysOnly, objectStoreNames[1]); 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( function testSporadicWrites(
...@@ -217,6 +302,18 @@ function testSporadicWrites( ...@@ -217,6 +302,18 @@ function testSporadicWrites(
if (numIndices) if (numIndices)
getValue = function (i) { return getNFieldObjectValue(i, numIndices); }; getValue = function (i) { return getNFieldObjectValue(i, numIndices); };
automation.setStatus("Creating database.");
var options = [];
for (var i=0; i < numIndices; ++i) {
var o = {};
o.indexName = "index " + i;
o.indexKeyPath = getNFieldName(i);
o.indexIsUnique = false;
o.indexIsMultiEntry = false;
options.push(o);
}
createDatabase(testName, objectStoreNames, onCreated, onError, options);
function onCreated(db) { function onCreated(db) {
automation.setStatus("Setting up test database."); automation.setStatus("Setting up test database.");
var transaction = getTransaction(db, objectStoreNames, "readwrite", var transaction = getTransaction(db, objectStoreNames, "readwrite",
...@@ -252,99 +349,4 @@ function testSporadicWrites( ...@@ -252,99 +349,4 @@ function testSporadicWrites(
putRandomValues(transaction, objectStoreNames, numWritesPerTransaction, putRandomValues(transaction, objectStoreNames, numWritesPerTransaction,
numKeys); numKeys);
} }
automation.setStatus("Creating database.");
var options = [];
for (var i=0; i < numIndices; ++i) {
var o = {};
o.indexName = "index " + i;
o.indexKeyPath = getNFieldName(i);
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]
];
var currentTest = 0;
function runNextTest() {
if (currentTest < tests.length) {
var test = tests[currentTest++].slice();
var f = test.shift();
test.push(runNextTest);
f.apply(null, test);
} else {
onAllTestsComplete();
}
}
function onAllTestsComplete() {
var overallDuration = Date.now() - overallTestStartTime;
automation.addResult("OverallTestDuration", overallDuration);
automation.setDone();
}
function test() {
runNextTest();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment