summaryrefslogtreecommitdiff
path: root/node_modules/webworker-threads/test/test12_precompiled_vs_normal.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/webworker-threads/test/test12_precompiled_vs_normal.js')
-rw-r--r--node_modules/webworker-threads/test/test12_precompiled_vs_normal.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/node_modules/webworker-threads/test/test12_precompiled_vs_normal.js b/node_modules/webworker-threads/test/test12_precompiled_vs_normal.js
new file mode 100644
index 0000000..c4f86af
--- /dev/null
+++ b/node_modules/webworker-threads/test/test12_precompiled_vs_normal.js
@@ -0,0 +1,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);
+