blob: 96459a4f945660ae2fb35d1a43adbf80614f82d0 [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/runner.js"></script>
<script>
const numberOfIterations = 20;
const numberOfItems = 5000;
// Delete database(s) for the test ahead of time.
var databaseName = "objectstore-delete-DB";
indexedDB.deleteDatabase(databaseName).onsuccess = function() {
startIteration();
}
var testGenerator = null;
var db = null;
var transaction = null;
PerfTestRunner.prepareToMeasureValuesAsync({
customIterationCount: numberOfIterations,
unit: 'ms',
done: function () {
transaction = null;
db = null;
testGenerator = null;
PerfTestRunner.gc();
}
});
function startIteration()
{
testGenerator = runIteration();
nextStep();
}
function nextStep()
{
testGenerator.next();
}
function *runIteration()
{
var openRequest = indexedDB.open(databaseName);
openRequest.onupgradeneeded = function(event) {
db = event.target.result;
var objectStore = db.createObjectStore('store');
}
openRequest.onsuccess = nextStep;
yield;
// Store items for deletion.
transaction = db.transaction('store', 'readwrite');
var objectStore = transaction.objectStore('store');
for (var i = 0; i < numberOfItems; ++i)
objectStore.add("value" + i, i);
transaction.oncomplete = function(event) {
nextStep();
}
yield;
var startTime = PerfTestRunner.now();
objectStore = db.transaction('store', 'readwrite').objectStore('store');
var completedDeletes = 0;
for (var i = 0; i < numberOfItems; ++i) {
objectStore.delete(i).onsuccess = function(event) {
if (++completedDeletes == numberOfItems)
nextStep();
}
}
yield;
if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
return;
setTimeout(startIteration, 0);
}
</script>
</body>
</html>