Skip to content

Commit 8a3b704

Browse files
JamesKyburzmcollina
authored andcommitted
github action to update benchmarks (#106)
* github action to update benchmarks * update to node 12 lts version * update github action to work without extra secrets
1 parent c3f73b9 commit 8a3b704

File tree

7 files changed

+110
-864
lines changed

7 files changed

+110
-864
lines changed

.github/workflows/benchmarks.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Node benchmarks
2+
3+
on:
4+
schedule:
5+
# * is a special character in YAML so you have to quote this string
6+
- cron: '0 0 1 * *'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v1
13+
- name: Use Node.js ${{ matrix.node-version }}
14+
uses: actions/setup-node@v1
15+
with:
16+
node-version: 12
17+
- name: run benchmarks
18+
run: |
19+
npm install
20+
npm start y 100 10 40
21+
- name: commit benchmarks
22+
run: |
23+
node_version=$(node --version)
24+
benchmark_title=$(cat << EOF
25+
# Benchmarks
26+
* __Machine:__ $(uname -a) | $(node -r os -p "\`\${os.cpus().length} vCPUs | \${Math.ceil(os.totalmem() / (Math.pow(1024, 3)))}GB\`").
27+
* __Method:__ \`autocannon -c 100 -d 40 -p 10 localhost:3000\` (two rounds; one to warm-up, one to measure).
28+
* __Node:__ \`$node_version\`
29+
* __Run:__ $(date)
30+
EOF)
31+
benchmark_table=$(node benchmark-compare.js -t -c)
32+
strip_readme=$(node -r fs -p 'fs.readFileSync("./README.md", "utf-8").split(/# Benchmarks/)[0]')
33+
git checkout master
34+
echo -e "${strip_readme:?}\n${benchmark_title:?}\n\n${benchmark_table}" > README.md
35+
git add README.md
36+
git config user.name 'Github Actions'
37+
git config user.email '<>'
38+
git commit -m "Add new benchmarks to README.md"
39+
- name: push benchmark changes
40+
uses: ad-m/github-push-action@master
41+
with:
42+
github_token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,3 @@ yarn.lock
5656
package-lock.json
5757

5858
# benchmark results
59-
results

benchmark-bench.js

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,75 @@
1-
#!/usr/bin/env node
21
'use strict'
32

43
const inquirer = require('inquirer')
54
const bench = require('./lib/bench')
65
const { choices, list } = require('./lib/packages')
6+
const argv = process.argv.slice(2)
77

8-
function select (callback) {
9-
inquirer.prompt([
8+
run().catch(err => {
9+
console.error(err)
10+
process.exit(1)
11+
})
12+
13+
async function run () {
14+
const options = await getBenchmarkOptions()
15+
const modules = options.all ? choices : await select(list)
16+
return bench(options, modules)
17+
}
18+
19+
async function getBenchmarkOptions () {
20+
if (argv.length) return parseArgv()
21+
return inquirer.prompt([
22+
{
23+
type: 'confirm',
24+
name: 'all',
25+
message: 'Do you want to run all benchmark tests?',
26+
default: false
27+
},
28+
{
29+
type: 'input',
30+
name: 'connections',
31+
message: 'How many connections do you need?',
32+
default: 100,
33+
validate (value) {
34+
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
35+
},
36+
filter: Number
37+
},
38+
{
39+
type: 'input',
40+
name: 'pipelining',
41+
message: 'How many pipelines do you need?',
42+
default: 10,
43+
validate (value) {
44+
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
45+
},
46+
filter: Number
47+
},
48+
{
49+
type: 'input',
50+
name: 'duration',
51+
message: 'How long should it take?',
52+
default: 40,
53+
validate (value) {
54+
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
55+
},
56+
filter: Number
57+
}
58+
])
59+
}
60+
61+
function parseArgv () {
62+
const [all, connections, pipelining, duration] = argv
63+
return {
64+
all: all === 'y',
65+
connections: +connections,
66+
pipelining: +pipelining,
67+
duration: +duration
68+
}
69+
}
70+
71+
async function select () {
72+
const result = await inquirer.prompt([
1073
{
1174
type: 'checkbox',
1275
message: 'Select packages',
@@ -25,52 +88,5 @@ function select (callback) {
2588
}
2689
}
2790
])
28-
.then(function (answers) {
29-
callback(answers.list)
30-
})
91+
return result.list
3192
}
32-
33-
inquirer.prompt([
34-
{
35-
type: 'confirm',
36-
name: 'all',
37-
message: 'Do you want to run all benchmark tests?',
38-
default: false
39-
},
40-
{
41-
type: 'input',
42-
name: 'connections',
43-
message: 'How many connections do you need?',
44-
default: 100,
45-
validate (value) {
46-
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
47-
},
48-
filter: Number
49-
},
50-
{
51-
type: 'input',
52-
name: 'pipelining',
53-
message: 'How many pipelines do you need?',
54-
default: 10,
55-
validate (value) {
56-
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
57-
},
58-
filter: Number
59-
},
60-
{
61-
type: 'input',
62-
name: 'duration',
63-
message: 'How long should it take?',
64-
default: 40,
65-
validate (value) {
66-
return !Number.isNaN(parseFloat(value)) || 'Please enter a number'
67-
},
68-
filter: Number
69-
}
70-
]).then((opts) => {
71-
if (!opts.all) {
72-
select(list => bench(opts, list))
73-
} else {
74-
bench(opts, choices)
75-
}
76-
})

benchmark-compare.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if (!choices.length) {
5151
head: ['', 'Router', 'Requests/s', 'Latency', 'Throughput/Mb']
5252
})
5353
if (commander.commandlineMdTable) {
54-
table.push([':--', '--:', ':-:', '--:', '--:', '--:'])
54+
table.push([':--', '--:', ':-:', '--:', '--:'])
5555
}
5656

5757
choices.forEach((result) => {

0 commit comments

Comments
 (0)