From 2d503ccb4bcfd0d26b175d2018e82068b1cbb5e6 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 2 Mar 2023 12:18:00 -0800 Subject: [PATCH] script to make a big tree for testing large walks --- .gitignore | 1 + .prettierignore | 2 ++ package-lock.json | 16 ++++++------ package.json | 4 +-- scripts/make-big-tree.js | 56 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 scripts/make-big-tree.js diff --git a/.gitignore b/.gitignore index 5ce40583..1d5bc735 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /coverage /test/fixtures /bench-working-dir +/scripts/fixture diff --git a/.prettierignore b/.prettierignore index 9fdb805a..fb94be32 100644 --- a/.prettierignore +++ b/.prettierignore @@ -7,3 +7,5 @@ /.nyc_output /coverage /benchmark +/scripts/fixture +/test/fixture diff --git a/package-lock.json b/package-lock.json index a664bb2f..e9eb2156 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,9 +19,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", @@ -2471,9 +2471,9 @@ } }, "node_modules/mkdirp": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-2.1.3.tgz", - "integrity": "sha512-sjAkg21peAG9HS+Dkx7hlG9Ztx7HLeKnvB3NQRcu/mltCVmvkF0pisbiTSfDVYTT86XEfZrTUosLdZLStquZUw==", + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-2.1.4.tgz", + "integrity": "sha512-Cy9cV4pRSl1o10i1dURTuRt4T04l0DkS1WZrT+Jir886OqOVkSv4FbOA7pgjhS8kEUrmm4kCRvv5var2iOCxpA==", "dev": true, "bin": { "mkdirp": "dist/cjs/src/bin.js" @@ -3103,9 +3103,9 @@ } }, "node_modules/rimraf": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.1.2.tgz", - "integrity": "sha512-BlIbgFryTbw3Dz6hyoWFhKk+unCcHMSkZGrTFVAx2WmttdBSonsdtRlwiuTbDqTKr+UlXIUqJVS4QT5tUzGENQ==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.1.3.tgz", + "integrity": "sha512-iyzalDLo3l5FZxxaIGUY7xI4Bf90Xt7pCipc1Mr7RsdU7H3538z+M0tlsUDrz0aHeGS9uNqiKHUJyTewwRP91Q==", "dev": true, "bin": { "rimraf": "dist/cjs/src/bin.js" diff --git a/package.json b/package.json index 000e6ba1..dcbaf001 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/make-big-tree.js b/scripts/make-big-tree.js new file mode 100644 index 00000000..a2543771 --- /dev/null +++ b/scripts/make-big-tree.js @@ -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') +})