commit
acbe09887a
3 changed files with 97 additions and 4 deletions
76
.github/workflows/bench.yaml
vendored
Normal file
76
.github/workflows/bench.yaml
vendored
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
name: Benchmark
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
bench:
|
||||||
|
name: Bench
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup node
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 14
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
profile: default
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Generate Cargo.lock
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: generate-lockfile
|
||||||
|
|
||||||
|
- name: Cache cargo registry
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.cargo/registry
|
||||||
|
key: bench-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
|
- name: Cache cargo index
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.cargo/git
|
||||||
|
key: bench-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
|
- name: Cache NPM dependencies
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: node_modules
|
||||||
|
key: bench-${{ hashFiles('yarn.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
npm-cache-
|
||||||
|
|
||||||
|
- name: 'Install dependencies'
|
||||||
|
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
|
||||||
|
|
||||||
|
- name: 'Build ts'
|
||||||
|
run: yarn build
|
||||||
|
|
||||||
|
- name: 'Build bench'
|
||||||
|
run: yarn build:bench
|
||||||
|
|
||||||
|
- name: 'Run benchmark'
|
||||||
|
run: yarn bench
|
||||||
|
|
||||||
|
- name: Store benchmark result
|
||||||
|
uses: rhysd/github-action-benchmark@v1
|
||||||
|
with:
|
||||||
|
tool: 'benchmarkjs'
|
||||||
|
output-file-path: bench.txt
|
||||||
|
comment-on-alert: true
|
||||||
|
github-token: ${{ secrets.GH_TOKEN }}
|
||||||
|
auto-push: true
|
||||||
|
comment-always: true
|
||||||
|
|
||||||
|
- name: Clear the cargo caches
|
||||||
|
run: |
|
||||||
|
cargo install cargo-cache --no-default-features --features ci-autoclean
|
||||||
|
cargo-cache
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -156,4 +156,5 @@ Temporary Items
|
||||||
# End of https://www.gitignore.io/api/macos
|
# End of https://www.gitignore.io/api/macos
|
||||||
scripts
|
scripts
|
||||||
|
|
||||||
sys/.node-headers
|
sys/.node-headers
|
||||||
|
bench.txt
|
||||||
|
|
|
@ -1,11 +1,27 @@
|
||||||
|
import { promises as fs } from 'fs'
|
||||||
|
import { join } from 'path'
|
||||||
|
|
||||||
|
import { Summary } from 'benny/lib/internal/common-types'
|
||||||
|
|
||||||
import { benchAsync } from './async'
|
import { benchAsync } from './async'
|
||||||
import { benchNoop } from './noop'
|
import { benchNoop } from './noop'
|
||||||
import { benchPlus } from './plus'
|
import { benchPlus } from './plus'
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
await benchNoop()
|
const output = [await benchNoop(), await benchPlus(), await benchAsync()]
|
||||||
await benchPlus()
|
.map(formatSummary)
|
||||||
await benchAsync()
|
.join('\n')
|
||||||
|
|
||||||
|
await fs.writeFile(join(process.cwd(), 'bench.txt'), output, 'utf8')
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSummary(summary: Summary): string {
|
||||||
|
return summary.results
|
||||||
|
.map(
|
||||||
|
(result) =>
|
||||||
|
`${summary.name}#${result.name} x ${result.ops} ops/sec ±${result.margin}% (${result.samples} runs sampled)`,
|
||||||
|
)
|
||||||
|
.join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
run().catch((e) => {
|
run().catch((e) => {
|
||||||
|
|
Loading…
Reference in a new issue