blob: 3666f80519930392cc2f080ef417019f9d587c3d [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/runner.js"></script>
<script>
var iterationCount = 20;
var numberDeleted = 0;
// Delete all databases for the test ahead of time.
var databasePrefix = "large-number-of-inserts-DB-";
for (var i = 0; i < iterationCount + 1; ++i) {
indexedDB.deleteDatabase(databasePrefix + i).onsuccess = function() {
if (++numberDeleted == iterationCount)
startIteration();
}
}
var testGenerator = null;
var db = null;
var currentIteration = 0;
PerfTestRunner.prepareToMeasureValuesAsync({
customIterationCount: iterationCount,
unit: 'ms',
done: function () {
db = null;
testGenerator = null;
PerfTestRunner.gc();
++currentIteration;
}
});
function startIteration()
{
testGenerator = runIteration();
nextStep();
}
function nextStep()
{
testGenerator.next();
}
var numberOfObjects = 100000;
var objectsToInsert = new Array(numberOfObjects);
for (var i = 0; i < numberOfObjects; ++i) {
objectsToInsert[i] = { data: Math.random() };
objectsToInsert[i].id = 'object_' + i;
}
function *runIteration()
{
var openRequest = indexedDB.open(databasePrefix + currentIteration);
openRequest.onupgradeneeded = function(event) {
db = event.target.result;
db.createObjectStore('objects', {keyPath: 'id'});
}
openRequest.onsuccess = nextStep;
yield;
var startTime = PerfTestRunner.now();
var objectStore = db.transaction('objects', 'readwrite').objectStore('objects');
objectStore.transaction.oncomplete = nextStep;
for (var i = 0; i < numberOfObjects; ++i)
objectStore.put(objectsToInsert[i]);
yield;
if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
return;
setTimeout(startIteration, 0);
}
</script>
</body>
</html>