Page 117 - Nodejs 교과서 개정2판
P. 117
$ node worker_data
from worker 101
from worker 102
job done
ߣীח ખ ؊ पੋ ઁ۽ ࣗࣻ ѐࣻܳ ҳೞח সਸ ਕழ झۨ٘ܳ ా೧ ೧ࠁѷणפ ࣗࣻܳ ח
স ো ݆ ٜযоח ੋ সੑפ
ݢ ਕழ झۨ٘ܳ ࢎਊೞ ঋח ઁੑפ
prime.js
const min = 2;
const max = 10000000;
const primes = [];
function generatePrimes(start, range) {
let isPrime = true;
const end = start + range;
for (let i = start; i < end; i++) {
for (let j = min; j < Math.sqrt(end); j++) {
if (i !== j && i % j === 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.push(i);
}
isPrime = true;
}
}
console.time('prime');
generatePrimes(min, max);
console.timeEnd('prime');
console.log(primes.length);
ࠗఠ ݅ө ं ী ࣗࣻо ݽف ݻ ѐ חܳ ঌইղח ٘ੑפ ٘ܳ प೯೧ࠁѷणפ
콘솔
$ node prime
prime: 8.745s
664579