blob: c4f86af2378cbb1afcc908c705f448bc41510589 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
var Threads= require('webworker-threads');
function A (err, msg) {
ctrA++;
this.eval(sourceText, A);
//process.stdout.write("\nA -> "+ msg);
}
function B (err, msg) {
ctrB++;
this.eval(precompiled, B);
//process.stdout.write("\nB -> "+ msg);
}
function ƒ () { return Math.random()* 10 }
var sourceText= '('+ ƒ+ ')()';
var precompiled= Threads.preCompile(sourceText);
var i= +process.argv[2] || 1;
console.log('Using '+ (i*2)+ ' threads');
while (i--) {
var a= Threads.create();
var b= Threads.create();
b.eval(precompiled, B);
a.eval(sourceText, A);
process.stdout.write('.');
}
ctrA= 0;
ctrB= 0;
var t= Date.now();
setInterval(function display () {
var e= Date.now()- t;
var tps= ((ctrA+ctrB)*1e3/e).toFixed(1);
var tpsA= (ctrA*1e3/e).toFixed(1);
var tpsB= (ctrB*1e3/e).toFixed(1);
process.stdout.write('\nt (ms) -> '+ e+ ', i -> '+ i+ ', tps -> '+ tps+ ', tpsA -> '+ tpsA+ ', tpsB -> '+ tpsB);
}, 1e3);
|