Rex Bench doesn't work from the command line
authormsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Aug 2017 22:33:27 +0000 (22:33 +0000)
committermsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Aug 2017 22:33:27 +0000 (22:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175349

Reviewed by Saam Barati.

Fixed cli.js to have the same set of benchmarks and .js files as the web
page driver.

Refactored the way benchmarks are run using a new Benchmark base class.  That
class will run the benchmark as well.  Eliminated the various runBenchmark()
functions that were used for individual tests.  This refactoring was threaded
into the web page driver as well.  Changed the iteration counts on many of the
individual benchmarks.  Also changed the inner loop count for the flight
planner test.

Eliminated Octane2/base.js as it isn't needed to run Octane2/RegExp with the
new test harness.  Eliminated other dead code in Octane2/regexp.js.

* RexBench/Basic/benchmark.js:
(BasicBenchmark):
(BasicBenchmark.prototype.runIteration): Deleted.
(runBenchmark): Deleted.
* RexBench/FlightPlanner/benchmark.js:
(FlightPlannerBenchmark):
(FlightPlannerBenchmark.prototype.runOnce):
(this.performance.performance.now.currentTime): Deleted.
(else.this.preciseTime.currentTime): Deleted.
(else.currentTime): Deleted.
(FlightPlannerBenchmark.prototype.runIteration): Deleted.
(FlightPlannerBenchmark.prototype.checkResults): Deleted.
(runBenchmark): Deleted.
* RexBench/Octane2/base.js: Removed.
* RexBench/Octane2/regexp.js:
* RexBench/basic_benchmark.js:
* RexBench/benchmark.js: Added.
(this.performance.performance.now.currentTime):
(else.this.preciseTime.currentTime):
(else.currentTime):
(Benchmark):
(Benchmark.prototype.runIterations):
(Benchmark.prototype.setup):
(Benchmark.prototype.runOnce):
(Benchmark.prototype.validate):
(Benchmark.prototype.tearDown):
* RexBench/cli.js:
* RexBench/flightplan_benchmark.js:
* RexBench/flightplan_unicode_benchmark.js:
* RexBench/octane2_benchmark.js:
* RexBench/stats.js:
(Stats.prototype.toString.return.span.0.span.span):
* RexBench/sunspider_benchmark.js:

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

13 files changed:
PerformanceTests/ChangeLog
PerformanceTests/RexBench/Basic/benchmark.js
PerformanceTests/RexBench/FlightPlanner/benchmark.js
PerformanceTests/RexBench/Octane2/base.js [deleted file]
PerformanceTests/RexBench/Octane2/regexp.js
PerformanceTests/RexBench/basic_benchmark.js
PerformanceTests/RexBench/benchmark.js [new file with mode: 0644]
PerformanceTests/RexBench/cli.js
PerformanceTests/RexBench/flightplan_benchmark.js
PerformanceTests/RexBench/flightplan_unicode_benchmark.js
PerformanceTests/RexBench/octane2_benchmark.js
PerformanceTests/RexBench/stats.js
PerformanceTests/RexBench/sunspider_benchmark.js

index 27a781c..d4792e6 100644 (file)
@@ -1,3 +1,57 @@
+2017-08-09  Michael Saboff  <msaboff@apple.com>
+
+        Rex Bench doesn't work from the command line
+        https://bugs.webkit.org/show_bug.cgi?id=175349
+
+        Reviewed by Saam Barati.
+
+        Fixed cli.js to have the same set of benchmarks and .js files as the web
+        page driver.
+
+        Refactored the way benchmarks are run using a new Benchmark base class.  That
+        class will run the benchmark as well.  Eliminated the various runBenchmark()
+        functions that were used for individual tests.  This refactoring was threaded
+        into the web page driver as well.  Changed the iteration counts on many of the
+        individual benchmarks.  Also changed the inner loop count for the flight
+        planner test.
+
+        Eliminated Octane2/base.js as it isn't needed to run Octane2/RegExp with the 
+        new test harness.  Eliminated other dead code in Octane2/regexp.js.
+
+        * RexBench/Basic/benchmark.js:
+        (BasicBenchmark):
+        (BasicBenchmark.prototype.runIteration): Deleted.
+        (runBenchmark): Deleted.
+        * RexBench/FlightPlanner/benchmark.js:
+        (FlightPlannerBenchmark):
+        (FlightPlannerBenchmark.prototype.runOnce):
+        (this.performance.performance.now.currentTime): Deleted.
+        (else.this.preciseTime.currentTime): Deleted.
+        (else.currentTime): Deleted.
+        (FlightPlannerBenchmark.prototype.runIteration): Deleted.
+        (FlightPlannerBenchmark.prototype.checkResults): Deleted.
+        (runBenchmark): Deleted.
+        * RexBench/Octane2/base.js: Removed.
+        * RexBench/Octane2/regexp.js:
+        * RexBench/basic_benchmark.js:
+        * RexBench/benchmark.js: Added.
+        (this.performance.performance.now.currentTime):
+        (else.this.preciseTime.currentTime):
+        (else.currentTime):
+        (Benchmark):
+        (Benchmark.prototype.runIterations):
+        (Benchmark.prototype.setup):
+        (Benchmark.prototype.runOnce):
+        (Benchmark.prototype.validate):
+        (Benchmark.prototype.tearDown):
+        * RexBench/cli.js:
+        * RexBench/flightplan_benchmark.js:
+        * RexBench/flightplan_unicode_benchmark.js:
+        * RexBench/octane2_benchmark.js:
+        * RexBench/stats.js:
+        (Stats.prototype.toString.return.span.0.span.span):
+        * RexBench/sunspider_benchmark.js:
+
 2017-08-07  Michael Saboff  <msaboff@apple.com>
 
         Use more accurate Russian keywords for RexBench/FlightPlanner Unicode mode
index f15678b..c5d63a9 100644 (file)
  */
 "use strict";
 
-class BasicBenchmark {
+class BasicBenchmark extends Benchmark {
     constructor(verbose = 0)
     {
-        this._verbose = verbose;
+        super(verbose);
     }
     
-    runIteration()
+    runOnce()
     {
         prepare("10 print \"hello, world!\"\n20 end");
         prepare("10 let x = 0\n20 let x = x + 1\n30 print x\n40 if x < 10 then 20\n50 end");
@@ -40,19 +40,3 @@ class BasicBenchmark {
         prepare("10 dim a(2000)\n20 for i = 2 to 2000\n30 let a(i) = 1\n40 next i\n50 for i = 2 to sqr(2000)\n60 if a(i) = 0 then 100\n70 for j = i ^ 2 to 2000 step i\n80 let a(j) = 0\n90 next j\n100 next i\n110 for i = 2 to 2000\n120 if a(i) = 0 then 140\n130 print i\n140 next i\n150 end\n");
     }
 }
-    
-function runBenchmark()
-{
-    const verbose = 0;
-    const numIterations = 150;
-    
-    let before = currentTime();
-    
-    let benchmark = new Benchmark(verbose);
-    
-    for (let iteration = 0; iteration < numIterations; ++iteration)
-        benchmark.runIteration();
-    
-    let after = currentTime();
-    return after - before;
-}
index 0386c21..0465e39 100644 (file)
  */
 "use strict";
 
-let currentTime;
-if (this.performance && performance.now)
-    currentTime = function() { return performance.now() };
-else if (this.preciseTime)
-    currentTime = function() { return preciseTime() * 1000; };
-else
-    currentTime = function() { return +new Date(); };
-
-class FlightPlannerBenchmark {
+class FlightPlannerBenchmark extends Benchmark {
     constructor(verbose = 0)
     {
-        this._verbose = verbose;
+        super(verbose);
     }
 
-    runIteration()
+    runOnce()
     {
-        for (let iteration = 0; iteration < 10; ++iteration) {
+        for (let i = 0; i < 5; i++) {
             setupUserWaypoints();
-            
+
             for (let flightPlan of expectedFlightPlans) {
                 flightPlan.reset();
                 flightPlan.resolveRoute();
             }
         }
-        this.checkResults();
     }
 
-    checkResults()
+    validate()
     {
         for (let flightPlan of expectedFlightPlans) {
             flightPlan.calculate();
@@ -59,26 +50,3 @@ class FlightPlannerBenchmark {
         }
     }
 }
-
-function runBenchmark()
-{
-    const verbose = 0;
-    const numIterations = 10;
-
-    let benchmark = new FlightPlannerBenchmark(verbose);
-
-    let before = currentTime();
-
-    for (let iteration = 0; iteration < numIterations; ++iteration)
-        benchmark.runIteration();
-    
-    let after = currentTime();
-
-    for (let iteration = 0; iteration < numIterations; ++iteration)
-        benchmark.checkResults();
-    
-    return after - before;
-}
-
-
-//  print("Benchmark ran in " + runBenchmark());
diff --git a/PerformanceTests/RexBench/Octane2/base.js b/PerformanceTests/RexBench/Octane2/base.js
deleted file mode 100644 (file)
index 600cc1d..0000000
+++ /dev/null
@@ -1,399 +0,0 @@
-// Copyright 2013 the V8 project authors. All rights reserved.
-// Copyright (C) 2015 Apple Inc. All rights reserved.
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//     * Redistributions of source code must retain the above copyright
-//       notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-//       copyright notice, this list of conditions and the following
-//       disclaimer in the documentation and/or other materials provided
-//       with the distribution.
-//     * Neither the name of Google Inc. nor the names of its
-//       contributors may be used to endorse or promote products derived
-//       from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-// Performance.now is used in latency benchmarks, the fallback is Date.now.
-var performance = performance || {};
-performance.now = (function() {
-  return performance.now       ||
-         performance.mozNow    ||
-         performance.msNow     ||
-         performance.oNow      ||
-         performance.webkitNow ||
-         Date.now;
-})();
-
-// Simple framework for running the benchmark suites and
-// computing a score based on the timing measurements.
-
-
-// A benchmark has a name (string) and a function that will be run to
-// do the performance measurement. The optional setup and tearDown
-// arguments are functions that will be invoked before and after
-// running the benchmark, but the running time of these functions will
-// not be accounted for in the benchmark score.
-function Benchmark(name, doWarmup, doDeterministic, run, setup, tearDown, latencyResult, minIterations) {
-  this.name = name;
-  this.doWarmup = doWarmup;
-  this.doDeterministic = doDeterministic;
-  this.run = run;
-  this.Setup = setup ? setup : function() { };
-  this.TearDown = tearDown ? tearDown : function() { };
-  this.latencyResult = latencyResult ? latencyResult : null; 
-  this.minIterations = minIterations ? minIterations : 32;
-}
-
-
-// Benchmark results hold the benchmark and the measured time used to
-// run the benchmark. The benchmark score is computed later once a
-// full benchmark suite has run to completion. If latency is set to 0
-// then there is no latency score for this benchmark.
-function BenchmarkResult(benchmark, time, latency) {
-  this.benchmark = benchmark;
-  this.time = time;
-  this.latency = latency;
-}
-
-
-// Automatically convert results to numbers. Used by the geometric
-// mean computation.
-BenchmarkResult.prototype.valueOf = function() {
-  return this.time;
-}
-
-
-// Suites of benchmarks consist of a name and the set of benchmarks in
-// addition to the reference timing that the final score will be based
-// on. This way, all scores are relative to a reference run and higher
-// scores implies better performance.
-function BenchmarkSuite(name, reference, benchmarks) {
-  this.name = name;
-  this.reference = reference;
-  this.benchmarks = benchmarks;
-  BenchmarkSuite.suites.push(this);
-}
-
-
-// Keep track of all declared benchmark suites.
-BenchmarkSuite.suites = [];
-
-// Scores are not comparable across versions. Bump the version if
-// you're making changes that will affect that scores, e.g. if you add
-// a new benchmark or change an existing one.
-BenchmarkSuite.version = '9';
-
-// Override the alert function to throw an exception instead.
-alert = function(s) {
-  throw "Alert called with argument: " + s;
-};
-
-
-// To make the benchmark results predictable, we replace Math.random
-// with a 100% deterministic alternative.
-BenchmarkSuite.ResetRNG = function() {
-  Math.random = (function() {
-    var seed = 49734321;
-    return function() {
-      // Robert Jenkins' 32 bit integer hash function.
-      seed = ((seed + 0x7ed55d16) + (seed << 12))  & 0xffffffff;
-      seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
-      seed = ((seed + 0x165667b1) + (seed << 5))   & 0xffffffff;
-      seed = ((seed + 0xd3a2646c) ^ (seed << 9))   & 0xffffffff;
-      seed = ((seed + 0xfd7046c5) + (seed << 3))   & 0xffffffff;
-      seed = ((seed ^ 0xb55a4f09) ^ (seed >>> 16)) & 0xffffffff;
-      return (seed & 0xfffffff) / 0x10000000;
-    };
-  })();
-}
-
-
-// Runs all registered benchmark suites and optionally yields between
-// each individual benchmark to avoid running for too long in the
-// context of browsers. Once done, the final score is reported to the
-// runner.
-BenchmarkSuite.RunSuites = function(runner) {
-  var continuation = null;
-  var suites = BenchmarkSuite.suites;
-  var length = suites.length;
-  BenchmarkSuite.scores = [];
-  var index = 0;
-  function RunStep() {
-    while (continuation || index < length) {
-      if (continuation) {
-        continuation = continuation();
-      } else {
-        var suite = suites[index++];
-        if (runner.NotifyStart) runner.NotifyStart(suite.name);
-        continuation = suite.RunStep(runner);
-      }
-      if (continuation && typeof window != 'undefined' && window.setTimeout) {
-        window.setTimeout(RunStep, 25);
-        return;
-      }
-    }
-
-    // show final result
-    if (runner.NotifyScore) {
-      var score = BenchmarkSuite.GeometricMean(BenchmarkSuite.scores);
-      var formatted = BenchmarkSuite.FormatScore(100 * score);
-      runner.NotifyScore(formatted);
-    }
-  }
-  RunStep();
-}
-
-
-// Counts the total number of registered benchmarks. Useful for
-// showing progress as a percentage.
-BenchmarkSuite.CountBenchmarks = function() {
-  var result = 0;
-  var suites = BenchmarkSuite.suites;
-  for (var i = 0; i < suites.length; i++) {
-    result += suites[i].benchmarks.length;
-  }
-  return result;
-}
-
-
-// Computes the geometric mean of a set of numbers.
-BenchmarkSuite.GeometricMean = function(numbers) {
-  var log = 0;
-  for (var i = 0; i < numbers.length; i++) {
-    log += Math.log(numbers[i]);
-  }
-  return Math.pow(Math.E, log / numbers.length);
-}
-
-
-// Computes the geometric mean of a set of throughput time measurements.
-BenchmarkSuite.GeometricMeanTime = function(measurements) {
-  var log = 0;
-  for (var i = 0; i < measurements.length; i++) {
-    log += Math.log(measurements[i].time);
-  }
-  return Math.pow(Math.E, log / measurements.length);
-}
-
-
-// Computes the average of the worst samples. For example, if percentile is 99, this will report the
-// average of the worst 1% of the samples.
-BenchmarkSuite.AverageAbovePercentile = function(numbers, percentile) {
-  // Don't change the original array.
-  numbers = numbers.slice();
-  
-  // Sort in ascending order.
-  numbers.sort(function(a, b) { return a - b; });
-  
-  // Now the elements we want are at the end. Keep removing them until the array size shrinks too much.
-  // Examples assuming percentile = 99:
-  //
-  // - numbers.length starts at 100: we will remove just the worst entry and then not remove anymore,
-  //   since then numbers.length / originalLength = 0.99.
-  //
-  // - numbers.length starts at 1000: we will remove the ten worst.
-  //
-  // - numbers.length starts at 10: we will remove just the worst.
-  var numbersWeWant = [];
-  var originalLength = numbers.length;
-  while (numbers.length / originalLength > percentile / 100)
-    numbersWeWant.push(numbers.pop());
-  
-  var sum = 0;
-  for (var i = 0; i < numbersWeWant.length; ++i)
-    sum += numbersWeWant[i];
-  
-  var result = sum / numbersWeWant.length;
-  
-  // Do a sanity check.
-  if (numbers.length && result < numbers[numbers.length - 1]) {
-    throw "Sanity check fail: the worst case result is " + result +
-      " but we didn't take into account " + numbers;
-  }
-  
-  return result;
-}
-
-
-// Computes the geometric mean of a set of latency measurements.
-BenchmarkSuite.GeometricMeanLatency = function(measurements) {
-  var log = 0;
-  var hasLatencyResult = false;
-  for (var i = 0; i < measurements.length; i++) {
-    if (measurements[i].latency != 0) {
-      log += Math.log(measurements[i].latency);
-      hasLatencyResult = true;
-    }
-  }
-  if (hasLatencyResult) {
-    return Math.pow(Math.E, log / measurements.length);
-  } else {
-    return 0;
-  }
-}
-
-
-// Converts a score value to a string with at least three significant
-// digits.
-BenchmarkSuite.FormatScore = function(value) {
-  if (value > 100) {
-    return value.toFixed(0);
-  } else {
-    return value.toPrecision(3);
-  }
-}
-
-// Notifies the runner that we're done running a single benchmark in
-// the benchmark suite. This can be useful to report progress.
-BenchmarkSuite.prototype.NotifyStep = function(result) {
-  this.results.push(result);
-  if (this.runner.NotifyStep) this.runner.NotifyStep(result.benchmark.name);
-}
-
-
-// Notifies the runner that we're done with running a suite and that
-// we have a result which can be reported to the user if needed.
-BenchmarkSuite.prototype.NotifyResult = function() {
-  var mean = BenchmarkSuite.GeometricMeanTime(this.results);
-  var score = this.reference[0] / mean;
-  BenchmarkSuite.scores.push(score);
-  if (this.runner.NotifyResult) {
-    var formatted = BenchmarkSuite.FormatScore(100 * score);
-    this.runner.NotifyResult(this.name, formatted);
-  }
-  if (this.reference.length == 2) {
-    var meanLatency = BenchmarkSuite.GeometricMeanLatency(this.results);
-    if (meanLatency != 0) {
-      var scoreLatency = this.reference[1] / meanLatency;
-      BenchmarkSuite.scores.push(scoreLatency);
-      if (this.runner.NotifyResult) {
-        var formattedLatency = BenchmarkSuite.FormatScore(100 * scoreLatency)
-        this.runner.NotifyResult(this.name + "Latency", formattedLatency);
-      }
-    }
-  }
-}
-
-
-// Notifies the runner that running a benchmark resulted in an error.
-BenchmarkSuite.prototype.NotifyError = function(error) {
-  if (this.runner.NotifyError) {
-    this.runner.NotifyError(this.name, error);
-  }
-  if (this.runner.NotifyStep) {
-    this.runner.NotifyStep(this.name);
-  }
-}
-
-
-// Runs a single benchmark for at least a second and computes the
-// average time it takes to run a single iteration.
-BenchmarkSuite.prototype.RunSingleBenchmark = function(benchmark, data) {
-  function Measure(data) {
-    var elapsed = 0;
-    var start = new Date();
-  
-  // Run either for 1 second or for the number of iterations specified
-  // by minIterations, depending on the config flag doDeterministic.
-    for (var i = 0; (benchmark.doDeterministic ? 
-      i<benchmark.minIterations : elapsed < 1000); i++) {
-      benchmark.run();
-      elapsed = new Date() - start;
-    }
-    if (data != null) {
-      data.runs += i;
-      data.elapsed += elapsed;
-    }
-  }
-
-  // Sets up data in order to skip or not the warmup phase.
-  if (!benchmark.doWarmup && data == null) {
-    data = { runs: 0, elapsed: 0 };
-  }
-
-  if (data == null) {
-    Measure(null);
-    return { runs: 0, elapsed: 0 };
-  } else {
-    Measure(data);
-    // If we've run too few iterations, we continue for another second.
-    if (data.runs < benchmark.minIterations) return data;
-    var usec = (data.elapsed * 1000) / data.runs;
-    var latencySamples = (benchmark.latencyResult != null) ? benchmark.latencyResult() : [0];
-    var percentile = 99.5;
-    var latency = BenchmarkSuite.AverageAbovePercentile(latencySamples, percentile) * 1000;
-    this.NotifyStep(new BenchmarkResult(benchmark, usec, latency));
-    return null;
-  }
-}
-
-
-// This function starts running a suite, but stops between each
-// individual benchmark in the suite and returns a continuation
-// function which can be invoked to run the next benchmark. Once the
-// last benchmark has been executed, null is returned.
-BenchmarkSuite.prototype.RunStep = function(runner) {
-  BenchmarkSuite.ResetRNG();
-  this.results = [];
-  this.runner = runner;
-  var length = this.benchmarks.length;
-  var index = 0;
-  var suite = this;
-  var data;
-
-  // Run the setup, the actual benchmark, and the tear down in three
-  // separate steps to allow the framework to yield between any of the
-  // steps.
-
-  function RunNextSetup() {
-    if (index < length) {
-      try {
-        suite.benchmarks[index].Setup();
-      } catch (e) {
-        suite.NotifyError(e);
-        return null;
-      }
-      return RunNextBenchmark;
-    }
-    suite.NotifyResult();
-    return null;
-  }
-
-  function RunNextBenchmark() {
-    try {
-      data = suite.RunSingleBenchmark(suite.benchmarks[index], data);
-    } catch (e) {
-      suite.NotifyError(e);
-      return null;
-    }
-    // If data is null, we're done with this benchmark.
-    return (data == null) ? RunNextTearDown : RunNextBenchmark();
-  }
-
-  function RunNextTearDown() {
-    try {
-      suite.benchmarks[index++].TearDown();
-    } catch (e) {
-      suite.NotifyError(e);
-      return null;
-    }
-    return RunNextSetup;
-  }
-
-  // Start out running the setup.
-  return RunNextSetup();
-}
index 44a560c..627b8c6 100644 (file)
 // affect how the regexps match their input.  Finally the strings are
 // scrambled to exercise the regexp engine on different input strings.
 
-
-var RegExpSuite = new BenchmarkSuite('RegExp', [910985], [
-  new Benchmark("RegExp", true, false, 
-    RegExpRun, RegExpSetup, RegExpTearDown, null, 16)
-]);
-
 var regExpBenchmark = null;
 
 function RegExpSetup() {
index b88a38d..c373263 100644 (file)
@@ -25,7 +25,7 @@
 "use strict";
 
 const BasicBenchmarkCode = String.raw`
-<script src="current_time.js"></script>
+<script src="benchmark.js"></script>
 <script src="Basic/ast.js"></script>
 <script src="Basic/basic.js"></script>
 <script src="Basic/caseless_map.js"></script>
@@ -36,15 +36,11 @@ const BasicBenchmarkCode = String.raw`
 <script src="Basic/state.js"></script>
 <script src="Basic/benchmark.js"></script>
 <script>
+"use strict";
 var results = [];
 var benchmark = new BasicBenchmark();
 var numIterations = 200;
-for (var i = 0; i < numIterations; ++i) {
-    var before = currentTime();
-    benchmark.runIteration();
-    var after = currentTime();
-    results.push(after - before);
-}
+benchmark.runIterations(numIterations, results);
 reportResult(results);
 </script>`;
 
@@ -52,7 +48,7 @@ reportResult(results);
 let runBasicBenchmark = null;
 if (!isInBrowser) {
     let sources = [
-        "current_time.js"
+        "benchmark.js"
         , "Basic/ast.js"
         , "Basic/basic.js"
         , "Basic/caseless_map.js"
@@ -64,7 +60,7 @@ if (!isInBrowser) {
         , "Basic/benchmark.js"
     ];
 
-    runBasicBenchmark = makeBenchmarkRunner(sources, "BasicBenchmark");
+    runBasicBenchmark = makeBenchmarkRunner(sources, "BasicBenchmark", 200);
 }
 
 const BasicBenchmarkRunner = {
diff --git a/PerformanceTests/RexBench/benchmark.js b/PerformanceTests/RexBench/benchmark.js
new file mode 100644 (file)
index 0000000..9503004
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+"use strict";
+
+let currentTime;
+if (this.performance && performance.now)
+    currentTime = function() { return performance.now() };
+else if (this.preciseTime)
+    currentTime = function() { return preciseTime() * 1000; };
+else
+    currentTime = function() { return +new Date(); };
+
+class Benchmark {
+    constructor(verbose = 0)
+    {
+        this._verbose = verbose;
+    }
+
+    runIterations(numIterations, results)
+    {
+        this.setup();
+
+        for (let iteration = 0; iteration < numIterations; ++iteration) {
+            let before = currentTime();
+            this.runOnce();
+            let after = currentTime();
+            results.push(after - before);
+        }
+
+        this.validate();
+        this.tearDown();
+    }
+    
+    setup()
+    {
+    }
+
+    runOnce()
+    {
+    }
+
+    validate()
+    {
+    }
+
+    tearDown()
+    {
+    }
+}
index fc002a1..cee51a9 100644 (file)
@@ -23,6 +23,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
+"use strict";
+
 const isInBrowser = false;
 
 function makeBenchmarkRunner(sources, benchmarkConstructor, numIterations = 200) {
@@ -34,12 +36,8 @@ function makeBenchmarkRunner(sources, benchmarkConstructor, numIterations = 200)
         this.results = [];
         var benchmark = new ${benchmarkConstructor}();
         var numIterations = ${numIterations};
-        for (var i = 0; i < numIterations; ++i) {
-            var before = currentTime();
-            benchmark.runIteration();
-            var after = currentTime();
-            results.push(after - before);
-        }
+    
+        benchmark.runIterations(numIterations, this.results);
     `;
     return function doRun() {
         let globalObjectOfScript = runString(source);
@@ -51,8 +49,11 @@ function makeBenchmarkRunner(sources, benchmarkConstructor, numIterations = 200)
 load("driver.js");
 load("results.js");
 load("stats.js");
+load("sunspider_benchmark.js");
+load("octane2_benchmark.js");
 load("basic_benchmark.js");
 load("flightplan_benchmark.js");
+load("flightplan_unicode_benchmark.js");
 load("glue.js");
 
 driver.start(6);
index 0e95c05..cb9e553 100644 (file)
 "use strict";
 
 const FlightPlannerBenchmarkCode = String.raw`
+<script src="benchmark.js"></script>
 <script src="FlightPlanner/airways.js"></script>
 <script src="FlightPlanner/waypoints.js"></script>
 <script src="FlightPlanner/flight_planner.js"></script>
 <script src="FlightPlanner/expectations.js"></script>
 <script src="FlightPlanner/benchmark.js"></script>
 <script>
+"use strict";
 var results = [];
 var benchmark = new FlightPlannerBenchmark();
 var numIterations = 200;
-for (var i = 0; i < numIterations; ++i) {
-    var before = currentTime();
-    benchmark.runIteration();
-    var after = currentTime();
-    results.push(after - before);
-}
+benchmark.runIterations(numIterations, results);
 reportResult(results);
 </script>`;
 
@@ -47,14 +44,15 @@ reportResult(results);
 let runFlightPlannerBenchmark = null;
 if (!isInBrowser) {
     let sources = [
-        "FlightPlanner/airways.js"
+        "benchmark.js"
+        , "FlightPlanner/airways.js"
         , "FlightPlanner/waypoints.js"
         , "FlightPlanner/flight_planner.js"
         , "FlightPlanner/expectations.js"
         , "FlightPlanner/benchmark.js"
     ];
 
-    runFlightPlannerBenchmark = makeBenchmarkRunner(sources, "FlightPlannerBenchmark");
+    runFlightPlannerBenchmark = makeBenchmarkRunner(sources, "FlightPlannerBenchmark", 200);
 }
 
 const FlightPlannerBenchmarkRunner = {
index 1b4b95d..f30e38e 100644 (file)
@@ -25,6 +25,7 @@
 "use strict";
 
 const FlightPlannerUnicodeBenchmarkCode = String.raw`
+<script src="benchmark.js"></script>
 <script src="FlightPlanner/airways.js"></script>
 <script src="FlightPlanner/waypoints.js"></script>
 <script src="FlightPlanner/use_unicode.js"></script>
@@ -32,15 +33,11 @@ const FlightPlannerUnicodeBenchmarkCode = String.raw`
 <script src="FlightPlanner/expectations.js"></script>
 <script src="FlightPlanner/benchmark.js"></script>
 <script>
+"use strict";
 var results = [];
 var benchmark = new FlightPlannerBenchmark();
 var numIterations = 200;
-for (var i = 0; i < numIterations; ++i) {
-    var before = currentTime();
-    benchmark.runIteration();
-    var after = currentTime();
-    results.push(after - before);
-}
+benchmark.runIterations(numIterations, results);
 reportResult(results);
 </script>`;
 
@@ -48,7 +45,8 @@ reportResult(results);
 let runFlightPlannerUnicodeBenchmark = null;
 if (!isInBrowser) {
     let sources = [
-        "FlightPlanner/airways.js"
+        "benchmark.js"
+        , "FlightPlanner/airways.js"
         , "FlightPlanner/waypoints.js"
         , "FlightPlanner/use_unicode.js"
         , "FlightPlanner/flight_planner.js"
@@ -56,11 +54,11 @@ if (!isInBrowser) {
         , "FlightPlanner/benchmark.js"
     ];
 
-    runFlightPlannerUnicodeBenchmark = makeBenchmarkRunner(sources, "FlightPlannerUnicodeBenchmark");
+    runFlightPlannerUnicodeBenchmark = makeBenchmarkRunner(sources, "FlightPlannerBenchmark", 200);
 }
 
 const FlightPlannerUnicodeBenchmarkRunner = {
-    name: "Flight Planner",
+    name: "Flight Planner - Unicode",
     code: FlightPlannerUnicodeBenchmarkCode,
     run: runFlightPlannerUnicodeBenchmark,
     cells: {}
index 46eb138..e01949f 100644 (file)
 "use strict";
 
 const Octane2RegExpBenchmarkCode = String.raw`
-<script src="current_time.js"></script>
-<script src="Octane2/base.js"></script>
+<script src="benchmark.js"></script>
 <script src="Octane2/regexp.js"></script>
+<script src="Octane2/benchmark.js"></script>
 <script>
+"use script";      
 var results = [];
-var numIterations = 40;
-BenchmarkSuite.ResetRNG();
-RegExpSetup();
-for (var i = 0; i < numIterations; ++i) {
-    var before = currentTime();
-    RegExpRun();
-    var after = currentTime();
-    results.push(after - before);
-}
-RegExpTearDown();
+var numIterations = 100;
+var benchmark = new Octane2RegExpBenchmark();
+benchmark.runIterations(numIterations, results);
 reportResult(results);
 </script>`;
 
@@ -47,16 +41,16 @@ reportResult(results);
 let runOctane2RegExpBenchmark = null;
 if (!isInBrowser) {
     let sources = [
-        "current_time.js"
-        , "Octane2/base.js"
+        "benchmark.js"
         , "Octane2/regexp.js"
+        , "Octane2/benchmark.js"
     ];
 
-    runOctaneRegExpBenchmark = makeBenchmarkRunner(sources, "Octane2RegExpBenchmark");
+    runOctane2RegExpBenchmark = makeBenchmarkRunner(sources, "Octane2RegExpBenchmark", 100);
 }
 
 const Octane2RegExpBenchmarkRunner = {
-    name: "Flight Planner",
+    name: "Octane2 RegExp",
     code: Octane2RegExpBenchmarkCode,
     run: runOctane2RegExpBenchmark,
     cells: {}
index 41c6ee2..9103e08 100644 (file)
@@ -92,8 +92,8 @@ class Stats {
         
         if (!result.n) {
             if (isInBrowser)
-                return `<span class="value">\&#8709;</span><span class="units">ms</span>`;
-            return `${this._prefix}\&#x2b14;ms`;
+                return `<span class="value">0</span><span class="units">ms</span>`;
+            return `${this._prefix}0ms`;
         }
         
         if (result.mean != result.mean)
index a34ec7d..34f8a9a 100644 (file)
 "use strict";
 
 const RegexDNABenchmarkCode = String.raw`
-<script src="current_time.js"></script>
+<script src="benchmark.js"></script>
 <script src="SunSpider/regex-dna.js"></script>
+<script src="SunSpider/benchmark.js"></script>
 <script>
+"use strict";
 var results = [];
-var numIterations = 20;
-for (var i = 0; i < numIterations; ++i) {
-    var before = currentTime();
-    runOnce();
-    var after = currentTime();
-    checkResult();
-    results.push(after - before);
-}
+var benchmark = new RegexDNABenchmark();
+var numIterations = 100;
+benchmark.runIterations(numIterations, results);
 reportResult(results);
 </script>`;
 
@@ -44,11 +41,12 @@ reportResult(results);
 let runRegexDNABenchmark = null;
 if (!isInBrowser) {
     let sources = [
-        "current_time.js"
+        "benchmark.js"
         , "SunSpider/regex-dna.js"
+        , "SunSpider/benchmark.js"
     ];
 
-    runRegexDNABenchmark = makeBenchmarkRunner(sources, "RegexDNABenchmark");
+    runRegexDNABenchmark = makeBenchmarkRunner(sources, "RegexDNABenchmark", 100);
 }
 
 const RegexDNABenchmarkRunner = {