Custom random

JavaScript performance comparison

Test case created

Info

Custom Math.random function.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    random = function() {
      var random = Math.random,
          random1 = random(),
          random2, random3;
   
      if (random() > 0.5) {
        random2 = 24;
      } else {
        random2 = 26;
      }
   
      if (random() < 0.5) {
        random3 = 3092;
      } else {
        random3 = 2094;
      }
   
      return random1 + +((new Date().getTime()).toString().charAt(
      random2) % random3);
    }
};
</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
In-built Random
Math.random();
pending…
Custom Random
random();
pending…

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

Compare results of other browsers

0 comments

Add a comment