From 71124ef35179cd9d72107fbcd9ad1334242d4aff Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 21 Aug 2023 17:24:49 +0100 Subject: [PATCH] hashx_cachegrind: Introduce u32be helper function This is going to be more obviously useful in a moment. --- crates/hashx/bench/benches/hashx_cachegrind.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/hashx/bench/benches/hashx_cachegrind.rs b/crates/hashx/bench/benches/hashx_cachegrind.rs index 7cda23e34..7f3dfb0c2 100644 --- a/crates/hashx/bench/benches/hashx_cachegrind.rs +++ b/crates/hashx/bench/benches/hashx_cachegrind.rs @@ -26,31 +26,38 @@ macro_rules! mk_c_equix { { $hashx_type:ident } => { { tor_c_equix::HashX::new(tor_c_equix::HashXType::$hashx_type) } } } +/// Helper, alias for `u32::to_be_bytes` +// +// Unfortunately, we can't just `use u32::to_be_bytes`. +fn u32be(s: u32) -> [u8; 4] { + s.to_be_bytes() +} + fn generate_interp_1000x() { let builder = mk_rust!(InterpretOnly); for s in 0_u32..1000_u32 { - let _ = black_box(builder.build(black_box(&s.to_be_bytes()))); + let _ = black_box(builder.build(black_box(&u32be(s)))); } } fn generate_interp_1000x_c() { let mut ctx = mk_c_equix!(HASHX_TYPE_INTERPRETED); for s in 0_u32..1000_u32 { - let _ = black_box(ctx.make(black_box(&s.to_be_bytes()))); + let _ = black_box(ctx.make(black_box(&u32be(s)))); } } fn generate_compiled_1000x() { let builder = mk_rust!(CompileOnly); for s in 0_u32..1000_u32 { - let _ = black_box(builder.build(black_box(&s.to_be_bytes()))); + let _ = black_box(builder.build(black_box(&u32be(s)))); } } fn generate_compiled_1000x_c() { let mut ctx = mk_c_equix!(HASHX_TYPE_COMPILED); for s in 0_u32..1000_u32 { - let _ = black_box(ctx.make(black_box(&s.to_be_bytes()))); + let _ = black_box(ctx.make(black_box(&u32be(s)))); } }