blob: 6bfbc5f37551c99e2bf1b6c65aa1980cb15585b7 [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/runner.js"></script>
<script>
const numberOfIterations = 20;
const numberOfItems = 10000;
const numberOfItemsToDelete = 5000;
// Delete database(s) for the test ahead of time.
var databaseName = "index-cursor-delete-DB-2";
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', { keyPath: 'uniqueIndexKey' });
objectStore.createIndex('uniqueIndex', 'uniqueIndexKey', { unique: true });
objectStore.createIndex('index', 'indexKey');
}
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.put({ value: 'value', uniqueIndexKey: "uniqueIndexKey" + i, indexKey: "index" + (i%2) });
transaction.oncomplete = function(event) {
nextStep();
}
yield;
var startTime = PerfTestRunner.now();
var index = db.transaction('store', 'readwrite').objectStore('store').index('index');
var completedDeletes = 0;
index.openCursor(IDBKeyRange.only('index1')).onsuccess = function(event) {
var cursor = event.target.result;
if(cursor) {
cursor.delete().onsuccess = function(event) {
if (++completedDeletes == numberOfItemsToDelete)
nextStep();
}
cursor.continue();
}
}
yield;
if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
return;
setTimeout(startIteration, 0);
}
</script>
</body>
</html>