blob: 6c5ac374b7342157f25727bd3784f44ce28a23d2 [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-responsiveness-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;
largestDelay = 0;
testGenerator = null;
PerfTestRunner.gc();
++currentIteration;
}
});
function startIteration()
{
testGenerator = runIteration();
nextStep();
}
function nextStep()
{
testGenerator.next();
}
var numberOfObjects = 50000;
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 objectStore = db.transaction('objects', 'readwrite').objectStore('objects');
objectStore.transaction.oncomplete = nextStep;
for (var i = 0; i < numberOfObjects; ++i)
objectStore.put(objectsToInsert[i]);
PerfTestRunner.startCheckingResponsiveness();
yield;
PerfTestRunner.stopCheckingResponsiveness();
if (!PerfTestRunner.measureValueAsync(PerfTestRunner.longestResponsivenessDelay()))
return;
setTimeout(startIteration, 0);
}
</script>
</body>
</html>