portfolio | contact
March
Friday the 9th

quick and dirty code benchmarking.

Friday, 3:17 PM
totally unscientific, buuuut if you want a rough idea of which way of doing something is faster....
function bench(fn, iterations){
    
    var start = new Date().getTime();
    for(var i = 0; i < iterations; i ++){
        fn();
    }
    var end  = new Date().getTime();
    return (end-start);

}


var fn1 = function(){ ... }
var fn2 = function(){ ... }

var times = 50000;

alert(bench(fn1,times) + " : " + bench(fn2, times));

◄ back