Skip to content

Commit

Permalink
Replace environment vars with arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
saul-jb committed Apr 8, 2024
1 parent e0a6613 commit 44e220c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 27 deletions.
6 changes: 4 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion packages/benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packages/benchmarks/src/import/import-bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImportBenchmark> => {
export const createImportBench = async (size: number, persistent: boolean): Promise<ImportBenchmark> => {
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()

Expand Down
47 changes: 37 additions & 10 deletions packages/benchmarks/src/import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -37,8 +64,8 @@ const dataPath = Path.join(packagePath, 'test-out')

async function main (): Promise<void> {
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))
Expand Down Expand Up @@ -112,10 +139,10 @@ async function main (): Promise<void> {
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`
}
}))

Expand Down
47 changes: 37 additions & 10 deletions packages/benchmarks/src/transfer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -37,8 +64,8 @@ const dataPath = Path.join(packagePath, 'test-out')

async function main (): Promise<void> {
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))
Expand Down Expand Up @@ -113,10 +140,10 @@ async function main (): Promise<void> {
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`
}
}))

Expand Down
4 changes: 2 additions & 2 deletions packages/benchmarks/src/transfer/transfer-bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransferBenchmark> => {
export const createTransferBench = async (size: number, persistent: boolean): Promise<TransferBenchmark> => {
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()))

Expand Down

0 comments on commit 44e220c

Please sign in to comment.