Skip to content

Instantly share code, notes, and snippets.

@fflorent
Forked from anonymous/gist:4418578
Last active December 10, 2015 10:08
Show Gist options
  • Save fflorent/4418708 to your computer and use it in GitHub Desktop.
Save fflorent/4418708 to your computer and use it in GitHub Desktop.
function loop(f)
{
for(var i = 0; i < 10000; i++)
f(Math.floor(Math.random() * 2 - 1));
}
console.time(">-1");
loop(function(index) index * eval("1") > -1);
console.timeEnd(">-1");
console.time("!=-1");
loop(function(index) index * eval("1") != -1);
console.timeEnd("!=-1");
console.time("!== -1");
loop(function(index) index * eval("1") !== -1);
console.timeEnd("!== -1");
console.time(">=0");
loop(function(index) index * eval("1") >= 0);
console.timeEnd(">=0");
console.time("~");
loop(function(index) ~index * eval("1"));
console.timeEnd("~");
/*
* My results:
*
* >-1: 625ms
* !=-1: 624ms
* !== -1: 616ms
* >=0: 612ms
* ~: 706ms
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment