From c7c22e3db1c826bcfb2bc66651ec480aae0d4ae0 Mon Sep 17 00:00:00 2001 From: yo mama Date: Sat, 4 Apr 2015 01:00:59 -0700 Subject: first --- .../benchmark/b01_fibonacci_server_threads.js | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 node_modules/webworker-threads/benchmark/b01_fibonacci_server_threads.js (limited to 'node_modules/webworker-threads/benchmark/b01_fibonacci_server_threads.js') diff --git a/node_modules/webworker-threads/benchmark/b01_fibonacci_server_threads.js b/node_modules/webworker-threads/benchmark/b01_fibonacci_server_threads.js new file mode 100644 index 0000000..dbedc87 --- /dev/null +++ b/node_modules/webworker-threads/benchmark/b01_fibonacci_server_threads.js @@ -0,0 +1,42 @@ + + +function fib (n) { + return (n < 2) ? 1 : fib(n-2)+ fib(n-1); +} + +//We're going to use n threads +var numThreads= +process.argv[3] || 1; +console.log("Using "+ numThreads+ " threads"); + +var threads= []; +var round_robin= 0; +var t= require('threads_a_gogo'); +while (numThreads--) { + threads.push(t.create().eval(fib)); +} + +var i= 0; +var n= 35; +function ƒ (req, res) { + if ((++i) % 10) { + res.end(" QUICK"); + process.stdout.write(" QUICK"); + } + else { + round_robin= (++round_robin) % threads.length; + threads[round_robin].eval('fib('+ n+ ')', function cb (err, data) { + if (err) throw err; + var txt= ' '+ data; + res.end(txt); + process.stdout.write(txt); + }); + } +} + + +var port= +process.argv[2] || 1234; +var http= require('http'); +http.globalAgent.maxSockets= 8192+2048; +http.createServer(ƒ).listen(port); +console.log('Fibonacci server (WITH THREADS) running @port: '+ port); + -- cgit v1.2.3-70-g09d2