Skip to content

Instantly share code, notes, and snippets.

@xk
Created September 13, 2012 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xk/3714498 to your computer and use it in GitHub Desktop.
Save xk/3714498 to your computer and use it in GitHub Desktop.
this_is_a_test
//2012-09-13 jorge@jorgechamorro.com
var ctr, i, t, k= 1e8;
function ƒ (i) { ctr+= i }
function begin () { i= k, ctr= 0; while (Date.now() === (t= Date.now())) ; }
function end (s,t) { console.log(s+ ((Date.now()- t)*1e6/k).toFixed(2)+ 'ns') }
begin();
while (i--) (function (i) { ctr+= i })(i);
end("(function (i) { ctr+= i })(i) -> ", t);
begin();
while (i--) ƒ(i);
end("ƒ(i) -> ", t);
/*
$ node test.js
(function (i) { ctr+= i })(i) -> 39.74ns
ƒ(i) -> 18.99ns
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment