Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bench: allow users to run benchmarks non-interactively #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions benchmark-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
const inquirer = require('inquirer')
const bench = require('./lib/bench')
const { choices, list } = require('./lib/packages')
const commander = require('commander')

function collect (value, previous) {
if (!choices.includes(value)) {
throw new TypeError(`Benchmark ${value} doesn't exist.`)
}
return previous.concat([value])
}

commander
.option('-a, --all', 'all')
.option('-c, --connections <connections>', 'connections', Number)
.option('-p, --pipelining <pipelining>', 'pipelining', Number)
.option('-d, --duration <duration>', 'duration', Number)
.option('-b, --benchmark <benchmarks>', 'benchmark', collect, [])
.parse(process.argv)

function select (callback) {
inquirer.prompt([
Expand Down Expand Up @@ -35,13 +51,15 @@ inquirer.prompt([
type: 'confirm',
name: 'all',
message: 'Do you want to run all benchmark tests?',
when: commander.all === undefined && commander.benchmark.length === 0,
default: false
},
{
type: 'input',
name: 'connections',
message: 'How many connections do you need?',
default: 100,
when: commander.connections === undefined,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
},
Expand All @@ -52,6 +70,7 @@ inquirer.prompt([
name: 'pipelining',
message: 'How many pipelines do you need?',
default: 10,
when: commander.pipelining === undefined,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
},
Expand All @@ -62,14 +81,21 @@ inquirer.prompt([
name: 'duration',
message: 'How long should it take?',
default: 40,
when: commander.duration === undefined,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
},
filter: Number
}
]).then((opts) => {
]).then((inquirerOpts) => {
const opts = { ...inquirerOpts, ...commander }

if (!opts.all) {
select(list => bench(opts, list))
if (opts.benchmark.length === 0) {
select(list => bench(opts, list))
} else {
bench(opts, opts.benchmark)
}
} else {
bench(opts, choices)
}
Expand Down