Add an IndexedDB perf test to PerformanceTests.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2016 00:10:58 +0000 (00:10 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2016 00:10:58 +0000 (00:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165430

Reviewed by Alex Christensen.

* IndexedDB/index-multientry.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209365 268f45cc-cd09-0410-ab3c-d52691b4dbfc

PerformanceTests/ChangeLog
PerformanceTests/IndexedDB/index-multientry.html [new file with mode: 0644]

index 176d39e..5d1a885 100644 (file)
@@ -1,3 +1,12 @@
+2016-12-05  Brady Eidson  <beidson@apple.com>
+
+        Add an IndexedDB perf test to PerformanceTests.
+        https://bugs.webkit.org/show_bug.cgi?id=165430
+
+        Reviewed by Alex Christensen.
+
+        * IndexedDB/index-multientry.html: Added.
+
 2016-12-02  Filip Pizlo  <fpizlo@apple.com>
 
         ES6SampleBench should report an average for Steady State so that all of the numbers are comparable
diff --git a/PerformanceTests/IndexedDB/index-multientry.html b/PerformanceTests/IndexedDB/index-multientry.html
new file mode 100644 (file)
index 0000000..5b86b02
--- /dev/null
@@ -0,0 +1,92 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../resources/runner.js"></script>
+<script>
+
+var iterationCount = 11;
+var numberDeleted = 0;
+
+// Delete all databases for the test ahead of time.
+for (var i = 0; i < iterationCount; ++i) {
+    indexedDB.deleteDatabase("index-multientry-DB-" + i).onsuccess = function() {
+        if (++numberDeleted == iterationCount)
+            startIteration();
+    }
+}
+
+var testGenerator = null;
+var db = null;
+var transaction = null;
+var currentIteration = 0;
+
+PerfTestRunner.prepareToMeasureValuesAsync({
+    customIterationCount: iterationCount,
+    unit: 'ms',
+    done: function () {
+        transaction = null;
+        db = null;
+        testGenerator = null;
+        PerfTestRunner.gc();
+        ++currentIteration;
+    }
+});
+
+function startIteration()
+{
+    testGenerator = runIteration();
+    nextStep();
+}
+
+function nextStep()
+{
+    testGenerator.next();
+}
+
+var object = { test: 'yo', indexKeys: [] };
+for (var i = 0; i < 1000; i++)
+    object.indexKeys.push('index_no_' + i);
+
+function *runIteration()
+{
+    var startTime = PerfTestRunner.now();
+
+    var openRequest = indexedDB.open("index-multientry-DB-" + currentIteration);
+    openRequest.onupgradeneeded = function(event) {
+        db = event.target.result;
+        db.createObjectStore('store').createIndex('index', 'indexKeys', { multiEntry: true });
+    }
+    openRequest.onsuccess = nextStep;
+
+    yield;
+
+    transaction = db.transaction('store', 'readwrite');
+    transaction.objectStore('store').put(object, 1);
+    transaction.oncomplete = nextStep;
+
+    yield;
+
+    var index = db.transaction('store').objectStore('store').index('index');
+
+    var completedGets = 0;
+    for (var i = 0; i < 1000; i++)
+    {
+        index.get('index_no_' + i).onsuccess = function (event) {
+            if (event.target.result.test != "yo")
+                alert("Expected 'yo', got '" + event.target.result.test + "'");
+
+            if (++completedGets == 1000)
+                nextStep();
+        };
+    }
+
+    yield;
+
+    if (!PerfTestRunner.measureValueAsync(PerfTestRunner.now() - startTime))
+        return;
+
+    setTimeout(startIteration, 0);
+}
+</script>
+</body>
+</html>