summaryrefslogtreecommitdiff
path: root/node_modules/webworker-threads/benchmark/pi_precompiled.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/webworker-threads/benchmark/pi_precompiled.js')
-rw-r--r--node_modules/webworker-threads/benchmark/pi_precompiled.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/node_modules/webworker-threads/benchmark/pi_precompiled.js b/node_modules/webworker-threads/benchmark/pi_precompiled.js
new file mode 100644
index 0000000..7139ac1
--- /dev/null
+++ b/node_modules/webworker-threads/benchmark/pi_precompiled.js
@@ -0,0 +1,50 @@
+
+
+var Threads= require('threads_a_gogo');
+
+
+function cb (err, msg) {
+ this.destroy();
+ ++i;
+ process.stdout.write('\n'+ msg + ' -> '+ this.id);
+}
+
+function pi () {
+ var π= 0;
+ var num= 4;
+ var den= 1;
+ var plus= true;
+
+ while (den < 1e7) {
+ if (plus) {
+ π+= num/den;
+ plus= false;
+ }
+ else {
+ π-= num/den;
+ plus= true;
+ }
+ den+= 2;
+ }
+ return π;
+}
+
+
+var i= +process.argv[2] || 1;
+console.log('Using '+ i+ ' threads');
+
+var precompiled= Threads.preCompile('('+ pi+ ')()');
+var t= Date.now();
+while (i--) {
+ Threads.create().eval(precompiled, cb);
+}
+
+
+i= 0;
+process.on('exit', function () {
+ t= Date.now()- t;
+ var tps= (i*1e3/t).toFixed(1);
+ console.log('\nTiempo total (ms) -> '+ t);
+ console.log('Threads por segundo -> '+ tps);
+ console.log('Total de threads ejecutadas -> '+ i);
+});