diff --git a/package-lock.json b/package-lock.json index dd16034a..9e456253 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30503,7 +30503,8 @@ }, "node_modules/yargs": { "version": "17.7.2", - "license": "MIT", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", @@ -30629,7 +30630,8 @@ "debug": "^4.3.4", "pretty-bytes": "^6.1.1", "tinybench": "^2.6.0", - "uint8arrays": "^5.0.3" + "uint8arrays": "^5.0.3", + "yargs": "^17.7.2" }, "devDependencies": { "aegir": "^42.2.4" diff --git a/packages/benchmarks/package.json b/packages/benchmarks/package.json index bc8ddd9c..1eb786cd 100644 --- a/packages/benchmarks/package.json +++ b/packages/benchmarks/package.json @@ -34,7 +34,8 @@ "debug": "^4.3.4", "pretty-bytes": "^6.1.1", "tinybench": "^2.6.0", - "uint8arrays": "^5.0.3" + "uint8arrays": "^5.0.3", + "yargs": "^17.7.2" }, "peerDependencies": { "@organicdesign/db-daemon": "^0.1.0" diff --git a/packages/benchmarks/src/import/import-bench.ts b/packages/benchmarks/src/import/import-bench.ts index 3aa7bf1c..41d2895f 100644 --- a/packages/benchmarks/src/import/import-bench.ts +++ b/packages/benchmarks/src/import/import-bench.ts @@ -4,12 +4,12 @@ import { packagePath } from '../utils/paths.js' import runNode from '../utils/run-node.js' import type { ImportBenchmark } from './interface.js' -export const createImportBench = async (size: number): Promise => { +export const createImportBench = async (size: number, persistent: boolean): Promise => { const dataPath = Path.join(packagePath, 'test-out') const name = `import-${size}` - const proc = await runNode(name) + const proc = await runNode(name, { persistent }) await proc.start() diff --git a/packages/benchmarks/src/import/index.ts b/packages/benchmarks/src/import/index.ts index dfcb5487..dc716073 100644 --- a/packages/benchmarks/src/import/index.ts +++ b/packages/benchmarks/src/import/index.ts @@ -4,16 +4,43 @@ import Path from 'path' import debug from 'debug' import prettyBytes from 'pretty-bytes' import { Bench } from 'tinybench' +import { hideBin } from 'yargs/helpers' +import yargs from 'yargs/yargs' import generateFile from '../utils/generate-file.js' import { packagePath } from '../utils/paths.js' import { createImportBench } from './import-bench.js' import type { ImportImplementation } from './interface.js' -const log = debug('bench:transfer') +const argv = await yargs(hideBin(process.argv)) + .option({ + iterations: { + alias: 'i', + type: 'number', + default: 3 + } + }) + .option({ + minTime: { + type: 'number', + default: 1 + } + }) + .option({ + precision: { + type: 'number', + default: 2 + } + }) + .option({ + persistent: { + alias: 'p', + type: 'boolean', + default: false + } + }) + .parse() -const ITERATIONS = parseInt(process.env.ITERATIONS ?? '3') -const MIN_TIME = parseInt(process.env.MIN_TIME ?? '1') -const RESULT_PRECISION = 2 +const log = debug('bench:import') const sizes = [ 0, // 1b @@ -26,7 +53,7 @@ const sizes = [ const impls: ImportImplementation[] = sizes.map(size => ({ name: `${prettyBytes(size)}`, - create: async () => createImportBench(size), + create: async () => createImportBench(size, argv.persistent), results: [], fileSize: size, size: 0, @@ -37,8 +64,8 @@ const dataPath = Path.join(packagePath, 'test-out') async function main (): Promise { const suite = new Bench({ - iterations: ITERATIONS, - time: MIN_TIME, + iterations: argv.iterations, + time: argv.minTime, async setup (task) { const impl = impls.find(({ name }) => task.name.includes(name)) @@ -112,10 +139,10 @@ async function main (): Promise { Size: prettyBytes(impl.size), Blocks: impl.blocks, 'Speed (Size)': `${prettyBytes(speed)}/s`, - 'Speed (Blocks)': `${bps.toFixed(RESULT_PRECISION)} blocks/s`, - 'Run Time': `${result?.period.toFixed(RESULT_PRECISION)}ms`, + 'Speed (Blocks)': `${bps.toFixed(argv.precision)} blocks/s`, + 'Run Time': `${result?.period.toFixed(argv.precision)}ms`, Runs: result?.samples.length, - p99: `${result?.p99.toFixed(RESULT_PRECISION)}ms` + p99: `${result?.p99.toFixed(argv.precision)}ms` } })) diff --git a/packages/benchmarks/src/transfer/index.ts b/packages/benchmarks/src/transfer/index.ts index 04888dc0..a0cf738e 100644 --- a/packages/benchmarks/src/transfer/index.ts +++ b/packages/benchmarks/src/transfer/index.ts @@ -4,16 +4,43 @@ import Path from 'path' import debug from 'debug' import prettyBytes from 'pretty-bytes' import { Bench } from 'tinybench' +import { hideBin } from 'yargs/helpers' +import yargs from 'yargs/yargs' import generateFile from '../utils/generate-file.js' import { packagePath } from '../utils/paths.js' import { createTransferBench } from './transfer-bench.js' import type { TransferImplementation } from './interface.js' -const log = debug('bench:transfer') +const argv = await yargs(hideBin(process.argv)) + .option({ + iterations: { + alias: 'i', + type: 'number', + default: 3 + } + }) + .option({ + minTime: { + type: 'number', + default: 1 + } + }) + .option({ + precision: { + type: 'number', + default: 2 + } + }) + .option({ + persistent: { + alias: 'p', + type: 'boolean', + default: false + } + }) + .parse() -const ITERATIONS = parseInt(process.env.ITERATIONS ?? '3') -const MIN_TIME = parseInt(process.env.MIN_TIME ?? '1') -const RESULT_PRECISION = 2 +const log = debug('bench:transfer') const sizes = [ 0, // 1b @@ -26,7 +53,7 @@ const sizes = [ const impls: TransferImplementation[] = sizes.map(size => ({ name: `${prettyBytes(size)}`, - create: async () => createTransferBench(size), + create: async () => createTransferBench(size, argv.persistent), results: [], fileSize: size, size: 0, @@ -37,8 +64,8 @@ const dataPath = Path.join(packagePath, 'test-out') async function main (): Promise { const suite = new Bench({ - iterations: ITERATIONS, - time: MIN_TIME, + iterations: argv.iterations, + time: argv.minTime, async setup (task) { const impl = impls.find(({ name }) => task.name.includes(name)) @@ -113,10 +140,10 @@ async function main (): Promise { Size: prettyBytes(impl.size), Blocks: impl.blocks, 'Speed (Size)': `${prettyBytes(speed)}/s`, - 'Speed (Blocks)': `${bps.toFixed(RESULT_PRECISION)} blocks/s`, - 'Run Time': `${result?.period.toFixed(RESULT_PRECISION)}ms`, + 'Speed (Blocks)': `${bps.toFixed(argv.precision)} blocks/s`, + 'Run Time': `${result?.period.toFixed(argv.precision)}ms`, Runs: result?.samples.length, - p99: `${result?.p99.toFixed(RESULT_PRECISION)}ms` + p99: `${result?.p99.toFixed(argv.precision)}ms` } })) diff --git a/packages/benchmarks/src/transfer/transfer-bench.ts b/packages/benchmarks/src/transfer/transfer-bench.ts index c4af0453..b7f47ee3 100644 --- a/packages/benchmarks/src/transfer/transfer-bench.ts +++ b/packages/benchmarks/src/transfer/transfer-bench.ts @@ -4,12 +4,12 @@ import { packagePath } from '../utils/paths.js' import runNode from '../utils/run-node.js' import type { TransferBenchmark } from './interface.js' -export const createTransferBench = async (size: number): Promise => { +export const createTransferBench = async (size: number, persistent: boolean): Promise => { const dataPath = Path.join(packagePath, 'test-out') const names = [...Array(2).keys()].map(i => `transfer-${size}-${i}`) - const procs = await Promise.all(names.map(async n => runNode(n))) + const procs = await Promise.all(names.map(async n => runNode(n, { persistent }))) await Promise.all(procs.map(async p => p.start()))