Software: Apache. PHP/7.3.33 uname -a: Linux acloudg.aryanict.com 4.18.0-513.9.1.lve.el8.x86_64 #1 SMP Mon Dec 4 15:01:22 UTC uid=1095(katebhospital) gid=1098(katebhospital) groups=1098(katebhospital) Safe-mode: OFF (not secure) /lib/node_modules/npm/node_modules/worker-farm/examples/pi/ drwxr-xr-x |
Viewing file: Select action/file-type: '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) }) |
:: Command execute :: | |
--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.4653 ]-- |