UNPKG

581 BJavaScriptView Raw
1
2
3var Threads= require('../');
4
5function cb (err, msg) {
6 i++;
7 ƒ();
8 //process.stdout.write('['+ this.id+ ']');
9}
10
11
12function ƒ () { process.nextTick(cb) }
13
14var i= +process.argv[2] || 1;
15console.log('Using '+ i+ ' threads');
16
17var threads= [];
18while (i--) {
19 ƒ();
20}
21
22i= 0;
23var t= Date.now();
24function display () {
25 var e= Date.now()- t;
26 var tps= (i*1e3/e).toFixed(1);
27 process.stdout.write('\nt (ms) -> '+ e+ ', i -> '+ i+ ', tps -> '+ tps+ ', [ '+ threads.map(percent)+ ' ]');
28 function percent (v) {
29 return Math.round(v/i*100);
30 }
31}
32
33
34
35setInterval(display, 1e3);