Add ability to run test many times for a better sense of performance metrics.
authorRobert Konigsberg <konigsberg@google.com>
Thu, 7 Apr 2011 15:29:50 +0000 (11:29 -0400)
committerRobert Konigsberg <konigsberg@google.com>
Thu, 7 Apr 2011 15:29:50 +0000 (11:29 -0400)
When run multiple times, this results in showing a nice dygraph of the
different runtimes. SELF-HOSTING! WE MUST GO DEEPER.

tests/dygraph-many-points-benchmark.html

index 29d80cf..c2f83f1 100644 (file)
     <p>Roll period (in points):
       <input type="text" id="roll_period_input" size="20"
               onchange="updatePlot();"></p>
+    <p>Repetitions:
+      <input type="text" id="repetitions" size="20"
+              onchange="updatePlot();"></p>
     <br>
     <br>
     <div id="plot"></div>
     <div id="message"></div>
+    <div id="metrics"></div>
 
     <script type="text/javascript">
       var plot;
@@ -39,6 +43,8 @@
             parseInt(document.getElementById('num_points_input').value);
         var numSeries =
             parseInt(document.getElementById('num_series_input').value);
+        var repetitions =
+            parseInt(document.getElementById('repetitions').value);
 
         var data = [];
         var xmin = 0.0;
         var rollPeriod = parseInt(
             document.getElementById('roll_period_input').value);
         var opts = {labels: labels, rollPeriod: rollPeriod};
-        var start = new Date();
-        plot = new Dygraph(plotDiv, data, opts);
-        var end = new Date();
-        document.getElementById('message').innerHTML =
-            "completed in " + (end - start) + " milliseconds.";
+        var durations = [];
+        for (var i = 0; i < repetitions; i++) {
+          var start = new Date();
+          plot = new Dygraph(plotDiv, data, opts);
+          var end = new Date();
+          durations.push(end - start);
+        }
+        if (repetitions == 1) {
+          document.getElementById('message').innerHTML =
+              "completed in " + (end - start) + " milliseconds.";
+        } else {
+          document.getElementById('message').innerHTML =
+              "Durations: " + durations;
+        }
+        updateMetrics(durations);
       };
 
+      updateMetrics = function(data) {
+        var d = "run,ms\n";
+        for (var i = 0; i < data.length; i++) {
+          d = d + i + "," + data[i] + "\n";
+        }
+        var g = new Dygraph(document.getElementById('metrics'), d,
+            {highlightCircleSize: 4});
+      }
+
       document.getElementById('num_points_input').value = '100';
       document.getElementById('num_series_input').value = '1';
       document.getElementById('roll_period_input').value = '1';
+      document.getElementById('repetitions').value = '1';
       updatePlot();
     </script>
   </body>