forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjectstore-clear.html
81 lines (66 loc) · 1.71 KB
/
objectstore-clear.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
74
75
76
77
78
79
80
81
<!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-clear-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 clear.
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');
objectStore.clear().onsuccess = function(event) {
nextStep();
}
yield;
if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
return;
setTimeout(startIteration, 0);
}
</script>
</body>
</html>