Math.random vs seeded rand

JavaScript performance comparison

Test case created by Avi Kohn

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var seed1 = Math.random(),
      seed2 = Math.floor(Math.random() * 1000);

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Math.random
Math.random();
pending…
Seeded random, decimal seed
var rand = Math.sin(seed1) * 10000;

rand - Math.floor(rand);
pending…
Seeded random, <= 1000 integer
var rand = Math.sin(seed2) * 10000;

rand - Math.floor(rand);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments