diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml new file mode 100644 index 000000000..128bdc498 --- /dev/null +++ b/.github/workflows/codspeed.yml @@ -0,0 +1,34 @@ +name: codspeed-benchmarks + +on: + push: + branches: + - "main" + pull_request: + # `workflow_dispatch` allows CodSpeed to trigger backtest + # performance analysis in order to generate initial data. + workflow_dispatch: + +jobs: + benchmarks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup rust toolchain, cache and cargo-codspeed binary + uses: moonrepo/setup-rust@v0 + with: + channel: stable + cache-target: release + bins: cargo-codspeed + + - name: Build the benchmark target(s) + working-directory: ./benchmarks + run: cargo codspeed build + + - name: Run the benchmarks + uses: CodSpeedHQ/action@v2 + with: + working-directory: ./benchmarks + run: cargo codspeed run + token: ${{ secrets.CODSPEED_TOKEN }} diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index e5439486f..689630cc4 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -53,3 +53,6 @@ harness = false name = "json_streaming" path = "benches/json_streaming.rs" harness = false + +[dev-dependencies] +codspeed-criterion-compat = "2.4.1" diff --git a/benchmarks/benches/arithmetic.rs b/benchmarks/benches/arithmetic.rs index bc98c15d5..cc497ccf8 100644 --- a/benchmarks/benches/arithmetic.rs +++ b/benchmarks/benches/arithmetic.rs @@ -1,10 +1,7 @@ -#[macro_use] -extern crate criterion; - #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -use criterion::Criterion; +use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; use nom::{ branch::alt, character::complete::{char, digit1, one_of, space0}, diff --git a/benchmarks/benches/http.rs b/benchmarks/benches/http.rs index e36014f3f..9ead6e546 100644 --- a/benchmarks/benches/http.rs +++ b/benchmarks/benches/http.rs @@ -3,7 +3,7 @@ #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -use criterion::*; +use codspeed_criterion_compat::*; use nom::{IResult, bytes::{tag, take_while1}, character:: char, multi::many, OutputMode, Parser, PResult, error::Error, Mode, sequence::{preceded, delimited, separated_pair, terminated, pair}, OutputM, Emit, Complete}; #[cfg_attr(rustfmt, rustfmt_skip)] diff --git a/benchmarks/benches/http_streaming.rs b/benchmarks/benches/http_streaming.rs index ca170fe39..031ffd49c 100644 --- a/benchmarks/benches/http_streaming.rs +++ b/benchmarks/benches/http_streaming.rs @@ -3,7 +3,7 @@ #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -use criterion::*; +use codspeed_criterion_compat::*; use nom::{IResult, bytes::streaming::{tag, take_while1}, character::streaming::{line_ending, char}, multi::many, Parser}; #[cfg_attr(rustfmt, rustfmt_skip)] diff --git a/benchmarks/benches/ini.rs b/benchmarks/benches/ini.rs index a769ed69a..c14b9b040 100644 --- a/benchmarks/benches/ini.rs +++ b/benchmarks/benches/ini.rs @@ -1,7 +1,7 @@ #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -use criterion::*; +use codspeed_criterion_compat::*; use nom::{ bytes::complete::take_while, diff --git a/benchmarks/benches/ini_str.rs b/benchmarks/benches/ini_str.rs index e46fa86ad..88fb313d6 100644 --- a/benchmarks/benches/ini_str.rs +++ b/benchmarks/benches/ini_str.rs @@ -1,7 +1,7 @@ #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -use criterion::*; +use codspeed_criterion_compat::*; use nom::{ bytes::complete::{is_a, tag, take_till, take_while}, diff --git a/benchmarks/benches/json.rs b/benchmarks/benches/json.rs index 8e8b841d6..94b84d31e 100644 --- a/benchmarks/benches/json.rs +++ b/benchmarks/benches/json.rs @@ -1,10 +1,7 @@ -#[macro_use] -extern crate criterion; - #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -use criterion::Criterion; +use codspeed_criterion_compat::*; use nom::{ branch::alt, bytes::{tag, take}, @@ -304,7 +301,7 @@ fn verbose_json(c: &mut Criterion) { .unwrap(); // println!("data:\n{:?}", json(data)); - c.bench_function("json vebose", |b| { + c.bench_function("json verbose", |b| { b.iter(|| { json::>() .process::>(data) diff --git a/benchmarks/benches/json_streaming.rs b/benchmarks/benches/json_streaming.rs index 3df76148a..0116a1600 100644 --- a/benchmarks/benches/json_streaming.rs +++ b/benchmarks/benches/json_streaming.rs @@ -1,10 +1,7 @@ -#[macro_use] -extern crate criterion; - #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -use criterion::Criterion; +use codspeed_criterion_compat::*; use nom::{ branch::alt, bytes::streaming::{tag, take}, diff --git a/benchmarks/benches/number.rs b/benchmarks/benches/number.rs index 802ad4ddd..d2d7d1772 100644 --- a/benchmarks/benches/number.rs +++ b/benchmarks/benches/number.rs @@ -1,10 +1,7 @@ -#[macro_use] -extern crate criterion; - #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -use criterion::Criterion; +use codspeed_criterion_compat::*; use nom::number::complete; fn parser(i: &[u8]) -> nom::IResult<&[u8], u64> {