Created
September 13, 2012 13:58
-
-
Save xk/3714498 to your computer and use it in GitHub Desktop.
this_is_a_test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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