Add an IndexedDB perf test to PerformanceTests.
[WebKit-https.git] / PerformanceTests / IndexedDB / index-multientry.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../resources/runner.js"></script>
5 <script>
6
7 var iterationCount = 11;
8 var numberDeleted = 0;
9
10 // Delete all databases for the test ahead of time.
11 for (var i = 0; i < iterationCount; ++i) {
12     indexedDB.deleteDatabase("index-multientry-DB-" + i).onsuccess = function() {
13         if (++numberDeleted == iterationCount)
14             startIteration();
15     }
16 }
17
18 var testGenerator = null;
19 var db = null;
20 var transaction = null;
21 var currentIteration = 0;
22
23 PerfTestRunner.prepareToMeasureValuesAsync({
24     customIterationCount: iterationCount,
25     unit: 'ms',
26     done: function () {
27         transaction = null;
28         db = null;
29         testGenerator = null;
30         PerfTestRunner.gc();
31         ++currentIteration;
32     }
33 });
34
35 function startIteration()
36 {
37     testGenerator = runIteration();
38     nextStep();
39 }
40
41 function nextStep()
42 {
43     testGenerator.next();
44 }
45
46 var object = { test: 'yo', indexKeys: [] };
47 for (var i = 0; i < 1000; i++)
48     object.indexKeys.push('index_no_' + i);
49
50 function *runIteration()
51 {
52     var startTime = PerfTestRunner.now();
53
54     var openRequest = indexedDB.open("index-multientry-DB-" + currentIteration);
55     openRequest.onupgradeneeded = function(event) {
56         db = event.target.result;
57         db.createObjectStore('store').createIndex('index', 'indexKeys', { multiEntry: true });
58     }
59     openRequest.onsuccess = nextStep;
60
61     yield;
62
63     transaction = db.transaction('store', 'readwrite');
64     transaction.objectStore('store').put(object, 1);
65     transaction.oncomplete = nextStep;
66
67     yield;
68
69     var index = db.transaction('store').objectStore('store').index('index');
70
71     var completedGets = 0;
72     for (var i = 0; i < 1000; i++)
73     {
74         index.get('index_no_' + i).onsuccess = function (event) {
75             if (event.target.result.test != "yo")
76                 alert("Expected 'yo', got '" + event.target.result.test + "'");
77
78             if (++completedGets == 1000)
79                 nextStep();
80         };
81     }
82
83     yield;
84
85     if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
86         return;
87
88     setTimeout(startIteration, 0);
89 }
90 </script>
91 </body>
92 </html>