Skip to content

Instantly share code, notes, and snippets.

@bga
Created September 6, 2010 20:32
Show Gist options
  • Save bga/567488 to your computer and use it in GitHub Desktop.
Save bga/567488 to your computer and use it in GitHub Desktop.
/*
Basic idea - measure cost of simplest operation of js in cpu cycles
asm
//var i = n;
mov EAX, n
// while(i--);
a: dec EAX
jnz a
in native x86 asm it costs 2 cycles
*/
// cpuFreq - cpu frequency
(function(n)
{
var d = new Date, i = n;
while(i--)
;
return (new Date - d)/1e3/n;
})(1e8)*cpuFreq;
/*
chrome7(v8)
~8
opera 10.60(Carakan)
~14
ie7(jscript5.7)
~168
ff3.6(trace monkey)
~11
ff4b3(Jaeger Monkey)
~8
besen r120
~33
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment