Skip to content

Instantly share code, notes, and snippets.

@koseki
Created November 27, 2022 16:20
Show Gist options
  • Save koseki/eaab8e48b50eb2386a541355b4fd7272 to your computer and use it in GitHub Desktop.
Save koseki/eaab8e48b50eb2386a541355b4fd7272 to your computer and use it in GitHub Desktop.
mv test
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]));
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()
{
"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