From a7d9991cf825adbfc2e1a07290355c0c6f8d9e2b Mon Sep 17 00:00:00 2001 From: Qinxuan Chen Date: Mon, 7 Oct 2024 03:49:55 +0800 Subject: [PATCH] chore: add encode/decode bench for `rustc-hex` (#15) chore: add encode/decode bench for rustc-hex --- Cargo.toml | 1 + benches/bench/main.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 41cd9c6..396015b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ faster-hex = { version = "0.10.0", default-features = false, features = [ ] } hex = { version = "~0.4.2", default-features = false } hex-literal = "0.4" +rustc-hex = "2.1" serde = { version = "1.0", default-features = false, features = ["derive"] } serde_json = { version = "1.0", default-features = false, features = ["alloc"] } diff --git a/benches/bench/main.rs b/benches/bench/main.rs index 06275df..e7e41c5 100644 --- a/benches/bench/main.rs +++ b/benches/bench/main.rs @@ -118,6 +118,19 @@ macro_rules! benches { } )* } + + mod rustc_hex { + use super::*; + + $( + #[bench] + fn $name(b: &mut Bencher) { + b.iter(|| { + ::rustc_hex::FromHex::from_hex::>(black_box($dec)) + }); + } + )* + } } mod decode_to_slice { @@ -209,6 +222,19 @@ macro_rules! benches { } )* } + + mod rustc_hex { + use super::*; + + $( + #[bench] + fn $name(b: &mut Bencher) { + b.iter(|| { + ::rustc_hex::ToHex::to_hex::(&black_box($enc)[..]) + }); + } + )* + } } mod encode_to_slice {