Created
September 16, 2015 07:26
-
-
Save ranma42/51d46e4a4664e388a8f7 to your computer and use it in GitHub Desktop.
Benchmark for slice comparison in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(iter_order)] | |
#![feature(test)] | |
extern crate test; | |
macro_rules! gen_bench { | |
($name:ident, $x: expr, $y: expr) => { | |
#[bench] | |
fn $name(b: &mut Bencher) { | |
b.iter(|| { black_box($x).$name(black_box($y)) }) | |
} | |
} | |
} | |
macro_rules! gen_bench2 { | |
($name:ident, $x: expr, $y: expr) => { | |
mod $name { | |
use test::{Bencher, black_box}; | |
gen_bench!(eq, $x, $y); | |
gen_bench!(cmp, $x, $y); | |
gen_bench!(partial_cmp, $x, $y); | |
gen_bench!(lt, $x, $y); | |
} | |
} | |
} | |
macro_rules! gen_bench3 { | |
($name:ident, $x: expr, $y: expr) => { | |
mod $name { | |
gen_bench2!(slice, &$x[..], &$y[..]); | |
gen_bench2!(iter, $x.iter(), $y.iter()); | |
} | |
} | |
} | |
gen_bench3!(bench_u8, [0u8; 10000], [0u8; 10000]); | |
gen_bench3!(bench_u16, [0u16; 10000], [0u16; 10000]); | |
gen_bench3!(bench_u32, [0u32; 10000], [0u32; 10000]); | |
gen_bench3!(bench_u64, [0u64; 10000], [0u64; 10000]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Applying a similar transformation to the implementation of
cmp
andpartial_cmp
for slices: