diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index aef481e..ab034a5 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -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 }} diff --git a/Cargo.toml b/Cargo.toml index b630d13..5392d02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/benches/jieba_benchmark.rs b/benches/jieba_benchmark.rs index 0988961..932b5b0 100644 --- a/benches/jieba_benchmark.rs +++ b/benches/jieba_benchmark.rs @@ -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;