Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Compare = function(fn1, fn2, i) {
var time = function(fn) {
var now = new Date();
fn();
return new Date() - now;
},
spinOn = function(fn, i) {
return function() { for (var ii = i;ii;ii--) fn(); }
},
fn1_time = time(spinOn(fn1, i)),
fn2_time = time(spinOn(fn2, i));
console.log('function 1 took: %o', fn1_time);
console.log('function 2 took: %o', fn2_time);
};
Compare(
function() { var a = true, b = 1; if (a) b; },
function() { var a = true, b = 1; !a && b; },
10000000
);
Compare(
function() { var a = false, b = 1; if (a) b; },
function() { var a = false, b = 1; !a && b; },
10000000
);
Compare(
function() { var a = true, b = 1, c = 2; if (a) b; else c; },
function() { var a = true, b = 1, c = 2; !a && b; a && c; },
10000000
);
Compare(
function() { var a = false, b = 1, c = 2; if (a) b; else c; },
function() { var a = false, b = 1, c = 2; !a && b; a && c; },
10000000
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment