Add IDB perf tests stressing key size.
[WebKit-https.git] / PerformanceTests / IndexedDB / large-string-keys.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../resources/runner.js"></script>
5 <script>
6
7 var iterationCount = 20;
8 var numberDeleted = 0;
9
10 // Delete all databases for the test ahead of time.
11 var databasePrefix = "large-string-keys-DB-";
12 for (var i = 0; i < iterationCount + 1; ++i) {
13     indexedDB.deleteDatabase(databasePrefix + i).onsuccess = function() {
14         if (++numberDeleted == iterationCount)
15             startIteration();
16     }
17 }
18
19 var testGenerator = null;
20 var db = null;
21 var currentIteration = 0;
22
23 PerfTestRunner.prepareToMeasureValuesAsync({
24     customIterationCount: iterationCount,
25     unit: 'ms',
26     done: function () {
27         db = null;
28         testGenerator = null;
29         PerfTestRunner.gc();
30         ++currentIteration;
31     }
32 });
33
34 function startIteration()
35 {
36     testGenerator = runIteration();
37     nextStep();
38 }
39
40 function nextStep()
41 {
42     testGenerator.next();
43 }
44
45 var baseString;
46 for (var i = 0; i < 100000; ++i)
47     baseString += "abcdefghijklmnopqrstuvwxyz";
48
49 var numberOfInserts = 10;
50 var array = new Array(numberOfInserts);
51 for (var i = 0; i < numberOfInserts; ++i)
52     array[i] = baseString + i;
53
54 function *runIteration()
55 {
56     var openRequest = indexedDB.open(databasePrefix + currentIteration);
57     openRequest.onupgradeneeded = function(event) {
58         db = event.target.result;
59         db.createObjectStore('arrays');
60     }
61     openRequest.onsuccess = nextStep;
62
63     yield;
64
65     var startTime = PerfTestRunner.now();
66
67     var objectStore = db.transaction('arrays', 'readwrite').objectStore('arrays');
68     objectStore.transaction.oncomplete = nextStep;
69
70     for (var i = 0; i < numberOfInserts; ++i)
71         objectStore.put("Some value!!!", array[i]);
72
73     yield;
74
75     if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
76         return;
77
78     setTimeout(startIteration, 0);
79 }
80
81 </script>
82 </body>
83 </html>