Skip to content

Commit

Permalink
script to make a big tree for testing large walks
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Mar 2, 2023
1 parent 3128b34 commit 2d503cc
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
/coverage
/test/fixtures
/bench-working-dir
/scripts/fixture
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
/.nyc_output
/coverage
/benchmark
/scripts/fixture
/test/fixture
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
"@types/tap": "^15.0.7",
"c8": "^7.12.0",
"eslint-config-prettier": "^8.6.0",
"mkdirp": "^2.0.0",
"mkdirp": "^2.1.4",
"prettier": "^2.8.3",
"rimraf": "^4.1.1",
"rimraf": "^4.1.3",
"tap": "^16.3.4",
"ts-node": "^10.9.1",
"typedoc": "^0.23.24",
Expand Down
56 changes: 56 additions & 0 deletions scripts/make-big-tree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env node
const mkdirp = require('mkdirp')
const { readFileSync } = require('fs')
const { writeFile } = require('fs/promises')
const rimraf = require('rimraf')
const filesPerDir = 10
const dirsPerDir = 5
const max = (module === require.main && +process.argv[2]) || 1_000_000
const { now } = performance
let lastReported = now()

const report = s => {
if (!process.stderr.isTTY) return
process.stderr.write('\r' + s.padEnd(40))
}

let made = 0
const makeStep = async dir => {
if (now() - lastReported > 250) report('growing: ' + made)
const promises = []
for (let i = 0; i < filesPerDir && made < max; i++) {
made++
promises.push(writeFile(`${dir}/${i}.txt`, ''))
}
await Promise.all(promises)

const childDirs = []
for (let i = 0; i < dirsPerDir && made < max; i++) {
made++
await mkdirp(`${dir}/${i}`)
childDirs.push(makeStep(`${dir}/${i}`))
}
await Promise.all(childDirs)
}

const make = async root => {
try {
const already = +readFileSync(`${root}/bigtree.txt`)
if (already === max) {
console.log('already done!')
return
}
} catch (_) {}
report('chop down previous bigtree...')
await rimraf(root + '/bigtree')
report('creating bigtree...')
report('\n')
await mkdirp(root + '/bigtree')
await makeStep(root + '/bigtree')
await writeFile(`${root}/bigtree.txt`, `${max}`)
}

make(__dirname + '/fixture').then(() => {
if (process.stderr.isTTY) process.stderr.write('\r'.padEnd(40) + '\r')
console.log('done')
})

0 comments on commit 2d503cc

Please sign in to comment.