blob: 2ba0e5a618923e312e3de9417e0280267abc529a [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/runner.js"></script>
<script>
const numberOfIterations = 20;
const numberOfItems = 5000;
const cursorStep = 2;
// Delete database(s) for the test ahead of time.
var databaseName = "objectstore-curosr-advance-DB";
indexedDB.deleteDatabase(databaseName).onsuccess = function() {
startIteration();
}
var testGenerator = null;
var db = null;
PerfTestRunner.prepareToMeasureValuesAsync({
customIterationCount: numberOfIterations,
unit: 'ms',
done: function () {
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');
for (var i = 0; i < numberOfItems; ++i)
objectStore.put("value" + i, i);
}
openRequest.onsuccess = nextStep;
yield;
var startTime = PerfTestRunner.now();
var objectStore = db.transaction('store').objectStore('store');
var expectedKey = 0;
objectStore.openCursor().onsuccess = function(event) {
var cursor = event.target.result;
if(cursor) {
if (cursor.key != expectedKey)
alert("Expected cursor.key '" + expectedKey + "', got '" + cursor.key + "'");
expectedKey += cursorStep;
cursor.advance(cursorStep);
} else {
nextStep();
}
}
yield;
if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
return;
setTimeout(startIteration, 0);
}
</script>
</body>
</html>