Skip to content

Commit

Permalink
allow benchmarks to be called with arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesKyburz committed Oct 7, 2019
1 parent 3e153b4 commit 2f16052
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 57 deletions.
17 changes: 1 addition & 16 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,7 @@ jobs:
- name: benchmarks
run: |
npm install
node -r child_process -e """
const ps = child_process.spawn('npm', ['start'])
const inputs=['y', '100', '10', '40']
const input = () => {
const next = inputs.shift()
if (next) {
setTimeout(() => {
ps.stdin.write(next + '\n')
setTimeout(input, 150)
}, 150)
}
}
ps.stdout.pipe(process.stdout)
ps.stderr.pipe(process.stderr)
input()
"""
npm start y 100 10 40
node_version=$(node --version)
benchmark_title=$(cat << EOF
# Benchmarks
Expand Down
95 changes: 54 additions & 41 deletions benchmark-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const inquirer = require('inquirer')
const bench = require('./lib/bench')
const { choices, list } = require('./lib/packages')
const argv = process.argv.slice(2)

function select (callback) {
inquirer.prompt([
Expand All @@ -30,47 +31,59 @@ function select (callback) {
})
}

inquirer.prompt([
{
type: 'confirm',
name: 'all',
message: 'Do you want to run all benchmark tests?',
default: false
},
{
type: 'input',
name: 'connections',
message: 'How many connections do you need?',
default: 100,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
(argv.length === 0
? inquirer.prompt([
{
type: 'confirm',
name: 'all',
message: 'Do you want to run all benchmark tests?',
default: false
},
filter: Number
},
{
type: 'input',
name: 'pipelining',
message: 'How many pipelines do you need?',
default: 10,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
{
type: 'input',
name: 'connections',
message: 'How many connections do you need?',
default: 100,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
},
filter: Number
},
filter: Number
},
{
type: 'input',
name: 'duration',
message: 'How long should it take?',
default: 40,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
{
type: 'input',
name: 'pipelining',
message: 'How many pipelines do you need?',
default: 10,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
},
filter: Number
},
filter: Number
}
]).then((opts) => {
if (!opts.all) {
select(list => bench(opts, list))
} else {
bench(opts, choices)
}
})
{
type: 'input',
name: 'duration',
message: 'How long should it take?',
default: 40,
validate (value) {
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
},
filter: Number
}
])
: (async () => {
const [all, connections, pipelining, duration] = argv
return {
all: all === 'y',
connections: +connections,
pipelining: +pipelining,
duration: +duration
}
})()
)
.then((opts) => {
if (!opts.all) {
select(list => bench(opts, list))
} else {
bench(opts, choices)
}
})

0 comments on commit 2f16052

Please sign in to comment.