Created
November 27, 2022 16:20
-
-
Save koseki/eaab8e48b50eb2386a541355b4fd7272 to your computer and use it in GitHub Desktop.
mv test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs-extra'); | |
async function main(size) { | |
for (let i = 0; i < 5; i++) { | |
console.log(i) | |
let s = ''; | |
for (let j = 0; j < size; j++) { | |
s += i | |
} | |
await fs.outputFile(`${i}.txt`, s) | |
} | |
} | |
main(Number(process.argv[2])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs-extra') | |
const sleep = (time) => new Promise(resolve => setTimeout(resolve, time)) | |
const wait = async (i) => { | |
console.log(i) | |
await fs.move(`${i}.txt`, 'out.txt') | |
return i | |
} | |
const main = async () => { | |
const idx = [0, 1, 2, 3, 4] | |
const start = new Date() | |
const values = await Promise.all(idx.map(wait)) | |
const end = new Date() | |
const elapsed = (end - start) / 1000 | |
console.log(`dudation: ${elapsed} sec`) | |
} | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "mv-test", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"start": "cp ./tmp/*.txt . && node index.js", | |
"generate": "node generate.js 10000000 && mkdir -p tmp && cp *.txt ./tmp", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"fs-extra": "^10.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment