From 3870a6c0db7dbbf720c11f812d5e0b94b57939c3 Mon Sep 17 00:00:00 2001 From: Dominik Nakamura Date: Fri, 6 Oct 2023 11:50:02 +0900 Subject: [PATCH] refactor: switch to more lightweight bench crate --- Cargo.lock | 380 +++++--------------------- Cargo.toml | 2 - crates/stef-benches/Cargo.toml | 3 +- crates/stef-benches/benches/parser.rs | 48 ++-- crates/stef-benches/benches/varint.rs | 133 ++++----- crates/stef-build/Cargo.toml | 2 +- crates/stef-derive/Cargo.toml | 2 +- crates/stef-parser/Cargo.toml | 2 +- 8 files changed, 161 insertions(+), 411 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 96dcdeb..84627c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,12 +26,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "anes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" - [[package]] name = "anstream" version = "0.6.4" @@ -91,12 +85,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - [[package]] name = "backtrace" version = "0.3.69" @@ -128,24 +116,12 @@ dependencies = [ "serde", ] -[[package]] -name = "bumpalo" -version = "3.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" - [[package]] name = "bytes" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" -[[package]] -name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" - [[package]] name = "cc" version = "1.0.83" @@ -161,33 +137,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "ciborium" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" -dependencies = [ - "ciborium-io", - "ciborium-ll", - "serde", -] - -[[package]] -name = "ciborium-io" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" - -[[package]] -name = "ciborium-ll" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" -dependencies = [ - "ciborium-io", - "half", -] - [[package]] name = "clap" version = "4.4.6" @@ -248,6 +197,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "condtype" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" + [[package]] name = "console" version = "0.15.7" @@ -261,86 +216,47 @@ dependencies = [ ] [[package]] -name = "criterion" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" -dependencies = [ - "anes", - "cast", - "ciborium", - "clap", - "criterion-plot", - "is-terminal", - "itertools", - "num-traits", - "once_cell", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.5.0" +name = "core_affinity" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +checksum = "622892f5635ce1fc38c8f16dfc938553ed64af482edb5e150bf4caedbfcb2304" dependencies = [ - "cast", - "itertools", + "libc", + "num_cpus", + "winapi", ] [[package]] -name = "crossbeam-deque" -version = "0.8.3" +name = "diff" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] -name = "crossbeam-epoch" -version = "0.9.15" +name = "divan" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +checksum = "1b83bf1f6d0621a46a00a7260700b15c608ae8b0aa65e830197ab216c24ca087" dependencies = [ - "autocfg", - "cfg-if", - "crossbeam-utils", - "memoffset", - "scopeguard", + "clap", + "condtype", + "core_affinity", + "divan-macros", + "linkme", + "regex-lite", ] [[package]] -name = "crossbeam-utils" -version = "0.8.16" +name = "divan-macros" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +checksum = "b6e12f661a0897d97d90d5f4d2c441ad947c560863b0e093b19dd8b309a1326c" dependencies = [ - "cfg-if", + "proc-macro2", + "quote", + "syn", ] -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - -[[package]] -name = "either" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" - [[package]] name = "encode_unicode" version = "0.3.6" @@ -403,12 +319,6 @@ dependencies = [ "regex", ] -[[package]] -name = "half" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" - [[package]] name = "heck" version = "0.4.1" @@ -474,30 +384,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "js-sys" -version = "0.3.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" -dependencies = [ - "wasm-bindgen", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -526,6 +412,26 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "linkme" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f948366ad5bb46b5514ba7a7a80643726eef08b06632592699676748c8bc33b" +dependencies = [ + "linkme-impl", +] + +[[package]] +name = "linkme-impl" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc28438cad73dcc90ff3466fc329a9252b1b8ba668eb0d5668ba97088cf4eef0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "linux-raw-sys" version = "0.4.8" @@ -544,15 +450,6 @@ version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" -[[package]] -name = "memoffset" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" -dependencies = [ - "autocfg", -] - [[package]] name = "miette" version = "5.10.0" @@ -602,12 +499,13 @@ dependencies = [ ] [[package]] -name = "num-traits" -version = "0.2.16" +name = "num_cpus" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "autocfg", + "hermit-abi 0.3.3", + "libc", ] [[package]] @@ -625,12 +523,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "oorandom" -version = "11.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" - [[package]] name = "owo-colors" version = "3.5.0" @@ -646,34 +538,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" -[[package]] -name = "plotters" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" - -[[package]] -name = "plotters-svg" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" -dependencies = [ - "plotters-backend", -] - [[package]] name = "pretty_assertions" version = "1.4.0" @@ -712,26 +576,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rayon" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - [[package]] name = "regex" version = "1.9.6" @@ -755,6 +599,12 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-lite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f96ede7f386ba6e910092e7ccdc04176cface62abebea07ed6b46d870ed95ca2" + [[package]] name = "regex-syntax" version = "0.7.5" @@ -780,12 +630,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - [[package]] name = "same-file" version = "1.0.6" @@ -795,12 +639,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "serde" version = "1.0.188" @@ -821,17 +659,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - [[package]] name = "similar" version = "2.2.1" @@ -857,10 +684,9 @@ dependencies = [ name = "stef-benches" version = "0.1.0" dependencies = [ - "criterion", + "divan", "indoc", "mimalloc", - "serde", "stef-parser", ] @@ -974,9 +800,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.37" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", @@ -1034,16 +860,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "unicode-ident" version = "1.0.12" @@ -1078,70 +894,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "wasm-bindgen" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" - -[[package]] -name = "web-sys" -version = "0.3.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "winapi" version = "0.3.9" @@ -1307,9 +1059,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.15" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +checksum = "037711d82167854aff2018dfd193aa0fef5370f456732f0d5a0c59b0f1b4b907" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 48eae2f..5f8d0c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,7 @@ license = "MIT" [workspace.dependencies] color-eyre = { version = "0.6.2", default-features = false } -eyre = "0.6.8" miette = "5.10.0" -serde = { version = "1.0.188", features = ["derive"] } [profile.release] lto = true diff --git a/crates/stef-benches/Cargo.toml b/crates/stef-benches/Cargo.toml index b557e04..2ce87fe 100644 --- a/crates/stef-benches/Cargo.toml +++ b/crates/stef-benches/Cargo.toml @@ -23,6 +23,5 @@ mimalloc = "0.1.39" stef-parser = { path = "../stef-parser" } [dev-dependencies] -criterion = "0.5.1" +divan = "0.1.0" indoc = "2.0.4" -serde = "1.0.188" diff --git a/crates/stef-benches/benches/parser.rs b/crates/stef-benches/benches/parser.rs index 4e7312a..6569cac 100644 --- a/crates/stef-benches/benches/parser.rs +++ b/crates/stef-benches/benches/parser.rs @@ -1,14 +1,18 @@ -use std::{fmt::Write, hint::black_box}; +use std::fmt::Write; -use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; +use divan::{black_box, Bencher}; use indoc::indoc; #[global_allocator] static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; -fn parser(c: &mut Criterion) { - c.bench_function("basic", |b| { - let input = indoc! {r#" +fn main() { + divan::main(); +} + +#[divan::bench] +fn basic(bencher: Bencher) { + let input = indoc! {r#" use other::one::Type1; use other::two; @@ -39,28 +43,25 @@ fn parser(c: &mut Criterion) { type SampleTyped = SampleStruct; "#}; - stef_parser::Schema::parse(input).unwrap(); + stef_parser::Schema::parse(input).unwrap(); - b.iter(|| stef_parser::Schema::parse(black_box(input))) - }); + bencher.bench(|| stef_parser::Schema::parse(black_box(input))); +} - for count in [1, 10, 100, 1000] { - let schema = generate_schema(count); - stef_parser::Schema::parse(&schema).unwrap(); +#[divan::bench(consts = [1, 10, 100, 1000])] +fn large_schema(bencher: Bencher) { + let schema = generate_schema(N); + stef_parser::Schema::parse(&schema).unwrap(); - c.bench_with_input(BenchmarkId::new("large_schema", count), &count, |b, _| { - b.iter(|| stef_parser::Schema::parse(black_box(&schema))) - }); - } + bencher.bench(|| stef_parser::Schema::parse(black_box(&schema))) +} - for count in [1, 10, 100, 1000] { - let schema = generate_schema(count); - let schema = stef_parser::Schema::parse(&schema).unwrap(); +#[divan::bench(consts = [1, 10, 100, 1000])] +fn print(bencher: Bencher) { + let schema = generate_schema(N); + let schema = stef_parser::Schema::parse(&schema).unwrap(); - c.bench_with_input(BenchmarkId::new("print", count), &count, |b, _| { - b.iter(|| black_box(&schema).to_string()) - }); - } + bencher.bench(|| black_box(&schema).to_string()) } fn generate_schema(count: usize) -> String { @@ -150,6 +151,3 @@ fn generate_schema(count: usize) -> String { input } - -criterion_group!(benches, parser); -criterion_main!(benches); diff --git a/crates/stef-benches/benches/varint.rs b/crates/stef-benches/benches/varint.rs index 4b24049..a968c49 100644 --- a/crates/stef-benches/benches/varint.rs +++ b/crates/stef-benches/benches/varint.rs @@ -1,75 +1,78 @@ -use std::hint::black_box; - -use criterion::{ - criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, PlotConfiguration, -}; +use divan::black_box; use stef_benches::varint; -fn varint(c: &mut Criterion) { - let mut g = c.benchmark_group("varint"); - g.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic)); +fn main() { + divan::main(); +} - for i in [ - 1, - u8::MAX.into(), - u16::MAX.into(), - u32::MAX.into(), - u64::MAX.into(), - u128::MAX, - ] { - g.bench_with_input(BenchmarkId::new("leb128", i), &i, |b, i| { - let mut buf = [0; 19]; - let value = *i; - b.iter(|| { - varint::postcard::encode(black_box(value), black_box(&mut buf)); - varint::postcard::decode(black_box(&buf)) - }); - }); - g.bench_with_input(BenchmarkId::new("bincode", i), &i, |b, i| { - let mut buf = [0; 19]; - let value = *i; - b.iter(|| { - varint::bincode::encode_u128(black_box(value), black_box(&mut buf)); - varint::bincode::decode_u128(black_box(&buf)) - }); - }); +trait Unsigned { + fn run(value: u128, buf: &mut [u8]) -> u128; +} + +trait Signed { + fn run(value: i128, buf: &mut [u8]) -> i128; +} + +struct Leb128; + +impl Unsigned for Leb128 { + fn run(value: u128, buf: &mut [u8]) -> u128 { + varint::postcard::encode(value, buf); + varint::postcard::decode(buf) + } +} + +impl Signed for Leb128 { + fn run(value: i128, buf: &mut [u8]) -> i128 { + varint::postcard::encode_i128(value, buf); + varint::postcard::decode_i128(buf) } - g.finish(); +} - let mut g = c.benchmark_group("varint_signed"); - g.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic)); +struct Bincode; - for i in [ - -1, - i8::MIN.into(), - i16::MIN.into(), - i32::MIN.into(), - i64::MIN.into(), - i128::MIN, - ] { - g.bench_with_input(BenchmarkId::new("leb128", i), &i, |b, i| { - let mut buf = [0; 19]; - let value = *i; - b.iter(|| { - varint::postcard::encode_i128(black_box(value), black_box(&mut buf)); - varint::postcard::decode_i128(black_box(&buf)) - }); - }); - g.bench_with_input(BenchmarkId::new("bincode", i), &i, |b, i| { - let mut buf = [0; 19]; - let value = *i; - b.iter(|| { - varint::bincode::encode_i128(black_box(value), black_box(&mut buf)); - varint::bincode::decode_i128(black_box(&buf)) - }); - }); +impl Unsigned for Bincode { + fn run(value: u128, buf: &mut [u8]) -> u128 { + varint::bincode::encode_u128(value, buf); + varint::bincode::decode_u128(buf) + } +} + +impl Signed for Bincode { + fn run(value: i128, buf: &mut [u8]) -> i128 { + varint::bincode::encode_i128(value, buf); + varint::bincode::decode_i128(buf) } - g.finish(); } -criterion_group! { - name = benches; - config = Criterion::default().plotting_backend(criterion::PlottingBackend::Plotters); - targets = varint +#[divan::bench( + types = [Leb128, Bincode], + consts = [ + 1, + u8::MAX as u128, + u16::MAX as u128, + u32::MAX as u128, + u64::MAX as u128, + u128::MAX, + ], +)] +fn unsigned() -> u128 { + let mut buf = [0; 19]; + T::run(black_box(N), black_box(&mut buf)) +} + +#[divan::bench( + types = [Leb128, Bincode], + consts = [ + -1, + i8::MIN as i128, + i16::MIN as i128, + i32::MIN as i128, + i64::MIN as i128, + i128::MIN, + ], +)] +fn signed() -> i128 { + let mut buf = [0; 19]; + T::run(black_box(N), black_box(&mut buf)) } -criterion_main!(benches); diff --git a/crates/stef-build/Cargo.toml b/crates/stef-build/Cargo.toml index b441b6a..c5f6e86 100644 --- a/crates/stef-build/Cargo.toml +++ b/crates/stef-build/Cargo.toml @@ -15,7 +15,7 @@ prettyplease = "0.2.15" proc-macro2 = { version = "1.0.67", default-features = false } quote = { version = "1.0.33", default-features = false } stef-parser = { path = "../stef-parser" } -syn = "2.0.37" +syn = "2.0.38" thiserror = "1.0.49" [dev-dependencies] diff --git a/crates/stef-derive/Cargo.toml b/crates/stef-derive/Cargo.toml index e37cefb..f9b6de6 100644 --- a/crates/stef-derive/Cargo.toml +++ b/crates/stef-derive/Cargo.toml @@ -15,4 +15,4 @@ proc-macro = true [dependencies] proc-macro2 = "1.0.67" quote = "1.0.33" -syn = "2.0.37" +syn = "2.0.38" diff --git a/crates/stef-parser/Cargo.toml b/crates/stef-parser/Cargo.toml index 5ea4866..af5f175 100644 --- a/crates/stef-parser/Cargo.toml +++ b/crates/stef-parser/Cargo.toml @@ -16,7 +16,7 @@ rustc-args = ["--cfg", "docsrs"] miette.workspace = true owo-colors = { version = "3.5.0", features = ["supports-colors"] } stef-derive = { path = "../stef-derive" } -winnow = "0.5.15" +winnow = "0.5.16" [dev-dependencies] indoc = "2.0.4"