We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Processor Name: Intel Core i5 Processor Speed: 2.3 GHz Number of Processors: 1 Total Number of Cores: 2 L2 Cache (per Core): 256 KB L3 Cache: 4 MB Memory: 16 GB
External Dependencies
Program:
const fs = require('fs') const path = require('path') const readline = require('readline') const basePath = '<path-to-files-directory>' const workerFarm = require('worker-farm') let worker = workerFarm(require.resolve('./worker.js')) const getFiles = function* () { for (let dir of fs.readdirSync(basePath)) { const dirPath = path.join(basePath, dir) yield (() => new Promise((resolve, reject) => { fs.readdir(dirPath, function (err, files) { if (err) { reject (err) } else { resolve (files.map(file => path.join(dirPath, file))) } }) }))() } } let total = 0 let count = 0 console.time('total') for (let promise of getFiles()) { promise .then(files => { files.map(filename => { worker(filename, (err, sum) => { if (err) { throw err } else { total += sum count++; if (count === 1000) { console.log(total) console.timeEnd('total') process.exit(0) } } }) }) }) .catch(err => console.error(err)) }
const fs = require('fs') const readline = require('readline') module.exports = function (filename, cb) { try { const lineReader = readline.createInterface({ input: fs.createReadStream(filename) }) let fileSum = 0 lineReader.on('line', line => { let lineSum = 0 let current = 0 for(let i = 0; i < line.length; i++) { let char = line[i] if (char != ',' ) { if (current === 0) { current = +char } else { current = (current * 10) + (+char) } } if ((char === ',') || (i === (line.length - 1))) { lineSum += current current = 0 } } fileSum += lineSum }) lineReader.on('close', () => { cb(null, fileSum) }) } catch (err) { cb(err) } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
External Dependencies
Program:
The text was updated successfully, but these errors were encountered: