Last active
October 9, 2019 13:44
-
-
Save StarpTech/958edf3920e13b08671998bf18683114 to your computer and use it in GitHub Desktop.
suggestion to https://github.com/fastify/benchmarks/pull/106
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
'use strict' | |
const inquirer = require('inquirer') | |
const bench = require('./lib/bench') | |
const { choices, list } = require('./lib/packages') | |
const argv = process.argv.slice(2) | |
async function select (callback) { | |
const result = await inquirer.prompt([ | |
{ | |
type: 'checkbox', | |
message: 'Select packages', | |
name: 'list', | |
choices: [ | |
new inquirer.Separator(' = The usual ='), | |
...list(), | |
new inquirer.Separator(' = The extras = '), | |
...list(true) | |
], | |
validate: function (answer) { | |
if (answer.length < 1) { | |
return 'You must choose at least one package.' | |
} | |
return true | |
} | |
} | |
]) | |
return answers.list | |
} | |
async function start() { | |
let result = null; | |
if (argv.length === 0) { | |
result = await 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'; | |
}, | |
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'; | |
}, | |
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'; | |
}, | |
filter: Number | |
} | |
]); | |
} else { | |
const [all, connections, pipelining, duration] = argv; | |
result = { | |
all: all === 'y', | |
connections: +connections, | |
pipelining: +pipelining, | |
duration: +duration | |
}; | |
} | |
if (!opts.all) { | |
const list = await select(); | |
bench(opts, list) | |
} else { | |
bench(opts, choices); | |
} | |
} | |
start().catch(err => { | |
console.error(err); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment