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