Skip to content

Commit

Permalink
codspeed integration (#1738)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed May 5, 2024
1 parent 6be62d3 commit 23cc370
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 15 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -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 }}
8 changes: 8 additions & 0 deletions benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 1 addition & 4 deletions benchmarks/benches/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benches/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benches/ini.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

use criterion::*;
use codspeed_criterion_compat::*;

use nom::{
bytes::complete::take_while,
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benches/ini_str.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
42 changes: 38 additions & 4 deletions benchmarks/benches/json.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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::<Error<&str>>(CANADA).unwrap();

// println!("data:\n{:?}", json(data));
c.bench_function("json canada", |b| {
b.iter(|| json::<Error<&str>>(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::<VerboseError<&str>>(data).unwrap();

// println!("data:\n{:?}", json(data));
c.bench_function("json verbose", |b| {
b.iter(|| json::<VerboseError<&str>>(data).unwrap());
});
}

fn verbose_canada_json(c: &mut Criterion) {
// test once to make sure it parses correctly
json::<VerboseError<&str>>(CANADA).unwrap();

// println!("data:\n{:?}", json(data));
c.bench_function("json canada verbose", |b| {
b.iter(|| json::<VerboseError<&str>>(CANADA).unwrap());
});
}

fn recognize_float_bytes(c: &mut Criterion) {
println!(
"recognize_float_bytes result: {:?}",
Expand Down
5 changes: 1 addition & 4 deletions benchmarks/benches/number.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down

0 comments on commit 23cc370

Please sign in to comment.