DYEBench: Move test states into benchmarkClient and remove the closure
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Jun 2014 21:12:00 +0000 (21:12 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Jun 2014 21:12:00 +0000 (21:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133438

Reviewed by Benjamin Poulain.

Moved all local variables in the closure wrapping benchmarkClient onto the object itself
and removed the closure to improve the readability of the code.

* DoYouEvenBench/Full.html:
* DoYouEvenBench/resources/main.js:
(window.benchmarkClient.willRunTest):
(window.benchmarkClient.didRunTest):
(window.benchmarkClient.didRunSuites):
(window.benchmarkClient.willStartFirstIteration):
(window.benchmarkClient.didFinishLastIteration):
(window.benchmarkClient._addResult): Moved.
(.): Deleted.

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

PerformanceTests/ChangeLog
PerformanceTests/DoYouEvenBench/Full.html
PerformanceTests/DoYouEvenBench/resources/main.js

index 48d997f..8e4d1bc 100644 (file)
@@ -1,5 +1,25 @@
 2014-06-01  Ryosuke Niwa  <rniwa@webkit.org>
 
+        DYEBench: Move test states into benchmarkClient and remove the closure
+        https://bugs.webkit.org/show_bug.cgi?id=133438
+
+        Reviewed by Benjamin Poulain.
+
+        Moved all local variables in the closure wrapping benchmarkClient onto the object itself
+        and removed the closure to improve the readability of the code.
+
+        * DoYouEvenBench/Full.html:
+        * DoYouEvenBench/resources/main.js:
+        (window.benchmarkClient.willRunTest):
+        (window.benchmarkClient.didRunTest):
+        (window.benchmarkClient.didRunSuites):
+        (window.benchmarkClient.willStartFirstIteration):
+        (window.benchmarkClient.didFinishLastIteration):
+        (window.benchmarkClient._addResult): Moved.
+        (.): Deleted.
+
+2014-06-01  Ryosuke Niwa  <rniwa@webkit.org>
+
         DYEBench: Split stylesheets and scripts in Full.html into separate files
         https://bugs.webkit.org/show_bug.cgi?id=133437
 
index 31aaff4..a0c238e 100644 (file)
@@ -2,7 +2,7 @@
 <html>
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-    <title>DoYouEvenBench v0.16</title>
+    <title>DoYouEvenBench v0.17</title>
     <link rel="stylesheet" href="resources/main.css">
     <script src="resources/main.js" defer></script>
     <script src="resources/benchmark-runner.js" defer></script>
index ef5996f..f197824 100644 (file)
@@ -1,56 +1,37 @@
-(function () {
-
-var values = [];
-var resultContainer = null;
-var title;
-var progressContainer;
-var progress;
-var iterationNumber = 0;
-var finishedTestCount = 0;
-
-function addResult(title, value) {
-    if (!resultContainer) {
-        resultContainer = document.createElement('table');
-        var caption = document.createElement('caption');
-        caption.textContent = document.title;
-        resultContainer.appendChild(caption);
-        document.body.appendChild(resultContainer);
-    }
-    if (!title)
-        return;
-    var row = document.createElement('tr');
-    var th = document.createElement('th');
-    th.textContent = title;
-    var td = document.createElement('td');
-    td.textContent = value;
-    row.appendChild(th);
-    row.appendChild(td);
-    resultContainer.appendChild(row);
-}
-
 window.benchmarkClient = {
     iterationCount: 20,
-    willRunTest: function () {
-        if (!progress) {
-            // We don't use the real progress element as some implementations animate it.
-            progressContainer = document.createElement('div');
-            progressContainer.appendChild(document.createElement('div'));
-            progressContainer.id = 'progressContainer';
-            document.body.appendChild(progressContainer);
-            progress = progressContainer.firstChild;
-        }
-        addResult();
-    },
+    _timeValues: [],
+    _finishedTestCount: 0,
+    _iterationNumber: 0,
+    _progress: null,
+    _progressCompleted: null,
+    _resultContainer: null,
+    willRunTest: function () { },
     didRunTest: function () {
-        finishedTestCount++;
-        progress.style.width = (finishedTestCount * 100 / this.testsCount) + '%';
+        this._finishedTestCount++;
+        this._progressCompleted.style.width = (this._finishedTestCount * 100 / this.testsCount) + '%';
     },
     didRunSuites: function (measuredValues) {
-        values.push(measuredValues.total);
-        iterationNumber++;
-        addResult('Iteration ' + iterationNumber, measuredValues.total.toFixed(2) + ' ms');
+        this._timeValues.push(measuredValues.total);
+        this._iterationNumber++;
+        this._addResult('Iteration ' + this._iterationNumber, measuredValues.total.toFixed(2) + ' ms');
+    },
+    willStartFirstIteration: function () {
+        // We don't use the real progress element as some implementations animate it.
+        this._progress = document.createElement('div');
+        this._progress.appendChild(document.createElement('div'));
+        this._progress.id = 'progressContainer';
+        document.body.appendChild(this._progress);
+        this._progressCompleted = this._progress.firstChild;
+
+        this._resultContainer = document.createElement('table');
+        var caption = document.createElement('caption');
+        caption.textContent = document.title;
+        this._resultContainer.appendChild(caption);
+        document.body.appendChild(this._resultContainer);
     },
     didFinishLastIteration: function () {
+        var values = this._timeValues;
         var sum = values.reduce(function (a, b) { return a + b; }, 0);
         var arithmeticMean = sum / values.length;
         var meanLabel = arithmeticMean.toFixed(2) + ' ms';
@@ -59,13 +40,21 @@ window.benchmarkClient = {
             var precentDelta = delta * 100 / arithmeticMean;
             meanLabel += ' \xb1 ' + delta.toFixed(2) + ' ms (' + precentDelta.toFixed(2) + '%)';
         }
-        addResult('Arithmetic Mean', meanLabel);
-        progressContainer.parentNode.removeChild(progressContainer);
+        this._addResult('Arithmetic Mean', meanLabel);
+        this._progress.parentNode.removeChild(this._progress);
+    },
+    _addResult: function (title, value) {
+        var row = document.createElement('tr');
+        var th = document.createElement('th');
+        th.textContent = title;
+        var td = document.createElement('td');
+        td.textContent = value;
+        row.appendChild(th);
+        row.appendChild(td);
+        this._resultContainer.appendChild(row);
     }
 }
 
-})();
-
 function startBenchmark() {
     var enabledSuites = Suites.filter(function (suite) { return !suite.disabled });
     var totalSubtestCount = enabledSuites.reduce(function (testsCount, suite) { return testsCount + suite.tests.length; }, 0);