Skip to content

Commit

Permalink
Update bench names
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Aug 28, 2023
1 parent 78af959 commit d5adb28
Showing 1 changed file with 66 additions and 58 deletions.
124 changes: 66 additions & 58 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,70 +26,78 @@ impl<const N: usize> fmt::Display for StdFormat<N> {

macro_rules! benches {
($($name:ident($value:expr))*) => {
mod encode_const_hex {
mod encode {
use super::*;

$(
#[bench]
fn $name(b: &mut Bencher) {
let buf = &mut [0; $value.len() * 2];

b.iter(|| {
let res = const_hex::encode_to_slice(black_box($value), black_box(buf));
black_box(res.unwrap());
});
}
)*
mod const_hex {
use super::*;

$(
#[bench]
fn $name(b: &mut Bencher) {
let buf = &mut [0; $value.len() * 2];

b.iter(|| {
let res = ::const_hex::encode_to_slice(black_box($value), black_box(buf));
black_box(res.unwrap());
});
}
)*
}

mod hex {
use super::*;

$(
#[bench]
fn $name(b: &mut Bencher) {
let buf = &mut [0; $value.len() * 2];

b.iter(|| {
let res = ::hex::encode_to_slice(black_box($value), black_box(buf));
black_box(res.unwrap());
});
}
)*
}
}

mod encode_hex {
mod format {
use super::*;

$(
#[bench]
fn $name(b: &mut Bencher) {
let buf = &mut [0; $value.len() * 2];

b.iter(|| {
let res = hex::encode_to_slice(black_box($value), black_box(buf));
black_box(res.unwrap());
});
}
)*
}

mod format_const_hex {
use super::*;

$(
#[bench]
fn $name(b: &mut Bencher) {
let mut buf = Vec::with_capacity($value.len() * 2);

b.iter(|| {
buf.clear();
write!(&mut buf, "{}", HexBufferFormat(black_box($value))).unwrap();
black_box(&buf);
});
}
)*
}

mod format_std {
use super::*;

$(
#[bench]
fn $name(b: &mut Bencher) {
let mut buf = Vec::with_capacity($value.len() * 2);

b.iter(|| {
buf.clear();
write!(&mut buf, "{}", StdFormat(black_box($value))).unwrap();
black_box(&buf);
});
}
)*
mod const_hex {
use super::*;

$(
#[bench]
fn $name(b: &mut Bencher) {
let mut buf = Vec::with_capacity($value.len() * 2);

b.iter(|| {
buf.clear();
write!(&mut buf, "{}", HexBufferFormat(black_box($value))).unwrap();
black_box(&buf);
});
}
)*
}

mod std {
use super::*;

$(
#[bench]
fn $name(b: &mut Bencher) {
let mut buf = Vec::with_capacity($value.len() * 2);

b.iter(|| {
buf.clear();
write!(&mut buf, "{}", StdFormat(black_box($value))).unwrap();
black_box(&buf);
});
}
)*
}
}
}
}
Expand Down

0 comments on commit d5adb28

Please sign in to comment.