Math.random vs Xorshift

JavaScript performance comparison

Revision 5 of this test case created

Info

Math.random() vs Xorshift.random()

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var x = 123456789,
        y = 362436069,
        z = 521288629,
        w = 88675123,
        v = 886756453;
   
    function uint32() {
        var t = (x ^ (x >>> 7)) >>> 0;
        x = y;
        y = z;
        z = w;
        w = v;
        v = (v ^ (v << 6)) ^ (t ^ (t << 13)) >>> 0;
        return ((y + y + 1) * v) >>> 0;
      };
   
      function fract53() {
        return random() + (uint32() & 0x1fffff) * 1.1102230246251565e-16;
      };
   
   
       function random() {
        return uint32() * 2.3283064365386963e-10;
      }
   
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Math.random()
a = Math.random();
pending…
Xorshift.random()
a = random();
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. Here’s a list of current revisions for this page:

0 comments

Add a comment