Commit 8d617a7b authored by kasperl@chromium.org's avatar kasperl@chromium.org

Removed the use of Math.random() and new Date() for building

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
parent fdb34fb4
...@@ -9,3 +9,21 @@ In addition to the benchmarks, the suite consists of the benchmark ...@@ -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 framework (base.js), which must be loaded before any of the individual
benchmark files, and two benchmark runners: An HTML version (run.html) benchmark files, and two benchmark runners: An HTML version (run.html)
and a standalone JavaScript version (run.js). 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.
...@@ -76,6 +76,24 @@ BenchmarkSuite.suites = []; ...@@ -76,6 +76,24 @@ BenchmarkSuite.suites = [];
BenchmarkSuite.version = '2 candidate'; 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 // Runs all registered benchmark suites and optionally yields between
// each individual benchmark to avoid running for too long in the // each individual benchmark to avoid running for too long in the
// context of browsers. Once done, the final score is reported to the // context of browsers. Once done, the final score is reported to the
......
...@@ -1406,7 +1406,9 @@ function rng_seed_int(x) { ...@@ -1406,7 +1406,9 @@ function rng_seed_int(x) {
// Mix in the current time (w/milliseconds) into the pool // Mix in the current time (w/milliseconds) into the pool
function rng_seed_time() { 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. // Initialize the pool with junk if needed.
......
...@@ -130,16 +130,21 @@ of the benchmark suite.</i></p> ...@@ -130,16 +130,21 @@ of the benchmark suite.</i></p>
<div class="title"><h3>Version 2</h3></div> <div class="title"><h3>Version 2</h3></div>
<p>For version 2 the crypto benchmark was fixed. Previously, the decryption <p>For version 2 the crypto benchmark was fixed. Previously, the
stage was given plaintext as input, which resulted in an error. Now, the decryption stage was given plaintext as input, which resulted in an
decryption stage is given the output of the encryption stage as input. The error. Now, the decryption stage is given the output of the
result is checked against the original plaintext. For this to give the correct encryption stage as input. The result is checked against the original
results the crypto objects are reset for each iteration of the benchmark. In plaintext. For this to give the correct results the crypto objects
addition, the size of the plain text has been increased a little.</p> 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
<p>Other benchmarks were fixed to do elementary verification of the results of Math.random() and new Date() to build an RNG pool has been
their calculations. This is to avoid accidentally obtaining scores that are removed. </p>
the result of an incorrect JavaScript engine optimization.</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"> </td><td style="text-align: center">
<div class="run"> <div class="run">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment