-
-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
script to make a big tree for testing large walks
- Loading branch information
Showing
5 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
/coverage | ||
/test/fixtures | ||
/bench-working-dir | ||
/scripts/fixture |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ | |
/.nyc_output | ||
/coverage | ||
/benchmark | ||
/scripts/fixture | ||
/test/fixture |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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') | ||
}) |