Uname : Linux premium36.web-hosting.com 4.18.0-513.24.1.lve.1.el8.x86_64 #1 SMP Thu May 9 15:10:09 UTC 2024 x86_64
Soft : LiteSpeed
Ip : 198.54.115.237
Port : 443
~
/
opt
/
alt
/
alt-nodejs10
/
root
/
lib
/
node_modules
/
npm
/
node_modules.bundled
/
worker-farm
/
examples
/
pi
[ HOME ]
Exec
Submit
index.js
'use strict' const CHILDREN = 500 , POINTS_PER_CHILD = 1000000 , FARM_OPTIONS = { maxConcurrentWorkers : require('os').cpus().length , maxCallsPerWorker : Infinity , maxConcurrentCallsPerWorker : 1 } let workerFarm = require('../../') , calcDirect = require('./calc') , calcWorker = workerFarm(FARM_OPTIONS, require.resolve('./calc')) , ret , start , tally = function (finish, err, avg) { ret.push(avg) if (ret.length == CHILDREN) { let pi = ret.reduce(function (a, b) { return a + b }) / ret.length , end = +new Date() console.log('π ≈', pi, '\t(' + Math.abs(pi - Math.PI), 'away from actual!)') console.log('took', end - start, 'milliseconds') if (finish) finish() } } , calc = function (method, callback) { ret = [] start = +new Date() for (let i = 0; i < CHILDREN; i++) method(POINTS_PER_CHILD, tally.bind(null, callback)) } console.log('Doing it the slow (single-process) way...') calc(calcDirect, function () { console.log('Doing it the fast (multi-process) way...') calc(calcWorker, process.exit) })
Submit
Back
Folder Name
Submit
File Name
File Content
Submit
Name
Type
Size
Permission
Last Modified
Actions
.
dir
-
0755
2024-03-03 10:41:29
..
dir
-
0755
2024-03-03 10:41:29
calc.js
text/plain
683 B
0644
2023-03-22 10:59:01
index.js
text/plain
1.18 KB
0644
2023-03-22 10:59:01