From 23cc3707b1b1554aefb5a4e7038cd729bd943ec2 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Sun, 21 Apr 2024 19:27:51 +0200 Subject: [PATCH] codspeed integration (#1738) --- .github/workflows/codspeed.yml | 34 ++++++++++++++++++++++++++ benchmarks/Cargo.toml | 8 ++++++ benchmarks/benches/arithmetic.rs | 5 +--- benchmarks/benches/http.rs | 2 +- benchmarks/benches/ini.rs | 2 +- benchmarks/benches/ini_str.rs | 2 +- benchmarks/benches/json.rs | 42 +++++++++++++++++++++++++++++--- benchmarks/benches/number.rs | 5 +--- 8 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/codspeed.yml 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 af58dbfe2..31a42ce70 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -42,3 +42,11 @@ harness = false name = "json" path = "benches/json.rs" harness = false + +[[bench]] +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 cab12224f..b6012cd16 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 4145d4a7b..e5ffb4bb8 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::complete::{tag, take_while1}, character::complete::{line_ending, char}, multi::many1}; #[cfg_attr(rustfmt, rustfmt_skip)] diff --git a/benchmarks/benches/ini.rs b/benchmarks/benches/ini.rs index b2f651b41..1df8dc988 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 7df62194a..33bb47b2d 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 7dd3f5a18..346a72d70 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::complete::{tag, take}, @@ -151,6 +148,43 @@ fn json_bench(c: &mut Criterion) { }); } +static CANADA: &str = include_str!("../canada.json"); +fn canada_json(c: &mut Criterion) { + // test once to make sure it parses correctly + json::>(CANADA).unwrap(); + + // println!("data:\n{:?}", json(data)); + c.bench_function("json canada", |b| { + b.iter(|| json::>(CANADA).unwrap()); + }); +} + +fn verbose_json(c: &mut Criterion) { + let data = " { \"a\"\t: 42, + \"b\": [ \"x\", \"y\", 12 ,\"\\u2014\", \"\\uD83D\\uDE10\"] , + \"c\": { \"hello\" : \"world\" + } + } "; + + // test once to make sure it parses correctly + json::>(data).unwrap(); + + // println!("data:\n{:?}", json(data)); + c.bench_function("json verbose", |b| { + b.iter(|| json::>(data).unwrap()); + }); +} + +fn verbose_canada_json(c: &mut Criterion) { + // test once to make sure it parses correctly + json::>(CANADA).unwrap(); + + // println!("data:\n{:?}", json(data)); + c.bench_function("json canada verbose", |b| { + b.iter(|| json::>(CANADA).unwrap()); + }); +} + fn recognize_float_bytes(c: &mut Criterion) { println!( "recognize_float_bytes result: {:?}", 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> {