forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-count.html
73 lines (59 loc) · 1.64 KB
/
index-count.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!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 = "index-count-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');
objectStore.createIndex('index', 'indexKey');
for (var i = 0; i < numberOfItems; i++)
objectStore.put( { value: 'value', indexKey: "index" + i }, i);
}
openRequest.onsuccess = nextStep;
yield;
var startTime = PerfTestRunner.now();
var index = db.transaction('store').objectStore('store').index('index');
index.count().onsuccess = function(event) {
if (event.target.result != numberOfItems)
alert("Expected " + numberOfItems + "items but get " + event.target.result);
nextStep();
}
yield;
if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
return;
setTimeout(startIteration, 0);
}
</script>
</body>
</html>