random floor vs round and modulo

Benchmark created on


Setup

var rand1 = function() {
      return Math.round(Math.random() * 6) % 6;
    }
    
    var rand2 = function() {
      return Math.floor(Math.random() * 6);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
rand1
var r = rand1();
ready
rand2
var r = rand2();
ready

Revisions

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