Removed the use of Math.random() and new Date() for building
authorkasperl@chromium.org <kasperl@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 2 Oct 2008 07:43:46 +0000 (07:43 +0000)
committerkasperl@chromium.org <kasperl@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 2 Oct 2008 07:43:46 +0000 (07:43 +0000)
the RNG pool in the crypto benchmark.
Review URL: http://codereview.chromium.org/6071

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@404 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

benchmarks/README.txt
benchmarks/base.js
benchmarks/crypto.js
benchmarks/run.html

index 59a6170..7058212 100644 (file)
@@ -9,3 +9,21 @@ In addition to the benchmarks, the suite consists of the benchmark
 framework (base.js), which must be loaded before any of the individual
 benchmark files, and two benchmark runners: An HTML version (run.html)
 and a standalone JavaScript version (run.js).
+
+
+Changes From Version 1 To Version 2
+===================================
+
+For version 2 the crypto benchmark was fixed.  Previously, the
+decryption stage was given plaintext as input, which resulted in an
+error.  Now, the decryption stage is given the output of the
+encryption stage as input.  The result is checked against the original
+plaintext.  For this to give the correct results the crypto objects
+are reset for each iteration of the benchmark.  In addition, the size
+of the plain text has been increased a little and the use of
+Math.random() and new Date() to build an RNG pool has been removed.
+
+Other benchmarks were fixed to do elementary verification of the
+results of their calculations.  This is to avoid accidentally
+obtaining scores that are the result of an incorrect JavaScript engine
+optimization.
index c5741d1..d00e390 100644 (file)
@@ -76,6 +76,24 @@ BenchmarkSuite.suites = [];
 BenchmarkSuite.version = '2 candidate';
 
 
+// To make the benchmark results predictable, we replace Math.random
+// with a 100% deterministic alternative.
+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 + 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
index 4308100..12b88ef 100644 (file)
@@ -1406,7 +1406,9 @@ function rng_seed_int(x) {
 
 // Mix in the current time (w/milliseconds) into the pool
 function rng_seed_time() {
-  rng_seed_int(new Date().getTime());
+  // Use pre-computed date to avoid making the benchmark 
+  // results dependent on the current date.
+  rng_seed_int(1122926989487);
 }
 
 // Initialize the pool with junk if needed.
index 80e5db8..2d49dbc 100644 (file)
@@ -130,16 +130,21 @@ of the benchmark suite.</i></p>
 
 <div class="title"><h3>Version 2</h3></div>
 
-<p>For version 2 the crypto benchmark was fixed.  Previously, the decryption
-stage was given plaintext as input, which resulted in an error.  Now, the
-decryption stage is given the output of the encryption stage as input.  The
-result is checked against the original plaintext.  For this to give the correct
-results the crypto objects are reset for each iteration of the benchmark.  In
-addition, the size of the plain text has been increased a little.</p>
-
-<p>Other benchmarks were fixed to do elementary verification of the results of
-their calculations.  This is to avoid accidentally obtaining scores that are
-the result of an incorrect JavaScript engine optimization.</p>
+<p>For version 2 the crypto benchmark was fixed.  Previously, the
+decryption stage was given plaintext as input, which resulted in an
+error.  Now, the decryption stage is given the output of the
+encryption stage as input.  The result is checked against the original
+plaintext.  For this to give the correct results the crypto objects
+are reset for each iteration of the benchmark.  In addition, the size
+of the plain text has been increased a little and the use of
+Math.random() and new Date() to build an RNG pool has been
+removed. </p>
+
+<p>Other benchmarks were fixed to do elementary verification of the
+results of their calculations.  This is to avoid accidentally
+obtaining scores that are the result of an incorrect JavaScript engine
+optimization.</p>
+
 
 </td><td style="text-align: center">
 <div class="run">