Created
April 11, 2012 21:00
-
-
Save xk/2362548 to your computer and use it in GitHub Desktop.
When threads_a_gogo beats node 2 to 1
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
/* | |
$ node bench.js | |
Threads_a_gogo JS thread -> 4624 (ms) 298607040 | |
Node's main JS thread -> 8471 (ms) 298607040 | |
Ratio: 1.83 times faster | |
*/ | |
function fib (n) { | |
return (n < 2) ? 1 : fib(n-2)+ fib(n-1); | |
} | |
function loop (n) { | |
var r= 0; | |
while (n--) r+= fib(35); | |
return r; | |
} | |
function cb (err, data) { | |
var save_t= t= Date.now()- t; | |
console.log("Threads_a_gogo JS thread -> ", t, '(ms) ', data); | |
thread.destroy(); | |
t= Date.now(); | |
data= loop(20); | |
t= Date.now()- t; | |
console.log("Node's main JS thread -> ", t, '(ms) ', data); | |
console.log('Ratio: '+ (t/save_t).toFixed(2)+ ' times faster'); | |
} | |
var thread= require('threads_a_gogo').create().eval(fib).eval(loop); | |
var t= Date.now(); | |
thread.eval('loop(20)', cb); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment