Random: Neil vs World

Benchmark created by Tomer Weller on


Description

Testing performance of the random function used in http://fab.cba.mit.edu/classes/863.14/people/index.html to select a random student vs. standard javascript Math.random()

Setup

function get_time() {
        if (window.performance != undefined){
                if (window.performance.now != undefined) {
                return performance.now();
                }               
        }
      return Date.now();
    }
    
    var t0 = get_time()
    
    function neil_random(max) {
       var dt = (get_time() - t0)/1000.0;
       return Math.floor(max * (dt - Math.floor(dt)));
    }
    
    
    function world_random(max) {
      return Math.floor(Math.random() * max);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Neil
neil_random(65);
ready
World
world_random(65);
ready

Revisions

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

  • Revision 1: published by Tomer Weller on