Skip to content

Instantly share code, notes, and snippets.

@bga
Created August 25, 2010 17:03
Show Gist options
  • Save bga/549865 to your computer and use it in GitHub Desktop.
Save bga/549865 to your computer and use it in GitHub Desktop.
var _abs = Math.abs;
_speedTest(
[
function(n)
{
var a = 0;
var i = n; while(i--)
{
a = (25173*a + 13849)&0xffff;
a -= 0x7fff;
if(a < 0) a = -a;
}
},
function(n)
{
var a = 0;
var i = n; while(i--)
{
a = (25173*a + 13849)&0xffff;
a -= 0x7fff;
a = (a^(a >> 31)) - (a >> 31);
}
},
function(n)
{
var a = 0;
var i = n; while(i--)
{
a = (25173*a + 13849)&0xffff;
a -= 0x7fff;
a = _abs(a);
}
}
],
100000000
);
/*
ie7 300000
0: 330 ms
1: 371 ms
2: 1021 ms
chrome5 10000000
0: 522 ms
1: 444 ms
2: 780 ms
opera10.60 20000000
0: 837 ms
1: 666 ms
2: 1320 ms
ff3.6 10000000
0: 7496 ms
1: 9101 ms
2: 8357 ms
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment