| <!DOCTYPE html> |
| <html> |
| <body> |
| <script src="../resources/runner.js"></script> |
| <script> |
| |
| // Delete database(s) for the test ahead of time. |
| var databaseName = "index-get-DB"; |
| indexedDB.deleteDatabase(databaseName).onsuccess = function() { |
| startIteration(); |
| } |
| |
| var testGenerator = null; |
| var db = null; |
| var transaction = null; |
| |
| PerfTestRunner.prepareToMeasureValuesAsync({ |
| customIterationCount: 10, |
| unit: 'ms', |
| done: function () { |
| transaction = null; |
| db = null; |
| testGenerator = null; |
| PerfTestRunner.gc(); |
| } |
| }); |
| |
| function startIteration() |
| { |
| testGenerator = runIteration(); |
| nextStep(); |
| } |
| |
| function nextStep() |
| { |
| testGenerator.next(); |
| } |
| |
| var numberOfEntries = 5000; |
| |
| 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 < numberOfEntries; i++) |
| objectStore.put( { test: 'yo', indexKey: "index" + i }, i); |
| } |
| openRequest.onsuccess = nextStep; |
| |
| yield; |
| |
| var startTime = PerfTestRunner.now(); |
| |
| var index = db.transaction('store').objectStore('store').index('index'); |
| var completedGets = 0; |
| for (var i = 0; i < numberOfEntries; i++) |
| { |
| index.get('index' + i).onsuccess = function (event) { |
| if (event.target.result.test != "yo") |
| alert("Expected 'yo', got '" + event.target.result.test + "'"); |
| |
| if (++completedGets == numberOfEntries) |
| nextStep(); |
| }; |
| } |
| |
| yield; |
| |
| if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime)) |
| return; |
| |
| setTimeout(startIteration, 0); |
| } |
| </script> |
| </body> |
| </html> |