Skip to content

Commit

Permalink
github action to update benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesKyburz committed Oct 8, 2019
1 parent c3f73b9 commit 330848b
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 854 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Node benchmarks

on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '0 0 1 * *'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: 10
- name: benchmarks
run: |
npm install
npm start y 100 10 40
npm start y 100 10 40
node_version=$(node --version)
benchmark_title=$(cat << EOF
# Benchmarks
* __Machine:__ $(uname -a) | $(node -r os -p -e "\`\${os.cpus().length} vCPUs | \${Math.ceil(os.totalmem() / (Math.pow(1024, 3)))}GB\`").
* __Method:__ \`autocannon -c 100 -d 40 -p 10 localhost:3000\` (two rounds; one to warm-up, one to measure).
* __Node:__ \`$node_version\`
* __Run:__ $(date)
EOF)
benchmark_table=$(node benchmark-compare.js -t -c)
strip_readme=$(node -r fs -p -e 'fs.readFileSync("./README.md", "utf-8").split(/# Benchmarks/)[0]')
git checkout master
echo -e "${strip_readme:?}\n${benchmark_title:?}\n\n${benchmark_table}" > README.md
git add README.md
git config user.name 'Github Actions'
git config user.email '<>'
git commit -m "Add new benchmarks to README.md"
git remote set-url --push origin https://${{ secrets.GITHUB_USERNAME }}:${{ secrets.GITHUB_REPO_TOKEN }}@github.com/fastify/benchmarks
git push
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ yarn.lock
package-lock.json

# benchmark results
results
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)
}
})
2 changes: 1 addition & 1 deletion benchmark-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if (!choices.length) {
head: ['', 'Router', 'Requests/s', 'Latency', 'Throughput/Mb']
})
if (commander.commandlineMdTable) {
table.push([':--', '--:', ':-:', '--:', '--:', '--:'])
table.push([':--', '--:', ':-:', '--:', '--:'])
}

choices.forEach((result) => {
Expand Down
Loading

0 comments on commit 330848b

Please sign in to comment.