Skip to content

Commit

Permalink
Use CodSpeed
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Apr 11, 2024
1 parent fb7c18e commit 2ffcf3b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 45 deletions.
63 changes: 23 additions & 40 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,38 @@
name: benches

on:
push:
branches:
- main
- "main"
pull_request:

name: Benchmark
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}-benches
cancel-in-progress: true

jobs:
benchmark:
name: Benchmark
benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: stable
override: true
- name: Cache cargo build
uses: Swatinem/rust-cache@v1
- name: Run benchmark
run: |
cargo bench --all-features --bench jieba_benchmark -- --output-format bencher | tee output.txt
components: rust-src

# Download previous benchmark result from cache (if exists)
- name: Download previous benchmark data
uses: actions/cache@v1
with:
path: ./cache
key: ${{ runner.os }}-benchmark
- uses: Swatinem/rust-cache@v2
continue-on-error: true

- name: Install cargo-codspeed
run: cargo install cargo-codspeed

- name: Build the benchmark target(s)
run: cargo codspeed build --all-features

# Run `github-action-benchmark` action
- name: Store benchmark result
uses: rhysd/github-action-benchmark@v1
- name: Run the benchmarks
uses: CodSpeedHQ/action@v2
with:
name: jieba_benchmark
# What benchmark tool the output.txt came from
tool: 'cargo'
# Where the output from the benchmark tool is stored
output-file-path: output.txt
# # Where the previous data file is stored
# external-data-json-path: ./cache/benchmark-data.json
# Workflow will fail when an alert happens
fail-on-alert: true
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Enable alert commit comment
comment-on-alert: true
alert-comment-cc-users: '@messense'
auto-push: true
run: cargo codspeed run --all-features
token: ${{ secrets.CODSPEED_TOKEN }}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ edition = '2021'
all-features = true

[dev-dependencies]
criterion = "0.5"
codspeed-criterion-compat = "2.4.1"
rand = "0.8"
wasm-bindgen-test = "0.3.0"

Expand Down
5 changes: 1 addition & 4 deletions benches/jieba_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#[macro_use]
extern crate criterion;

use criterion::{black_box, Criterion, Throughput};
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Criterion};
use jieba_rs::{Jieba, KeywordExtract, TextRank, TfIdf, TokenizeMode};
use lazy_static::lazy_static;

Expand Down

0 comments on commit 2ffcf3b

Please sign in to comment.