From e8b114f23ed003df2de571868a0bda35a39379d1 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Tue, 14 Mar 2023 23:40:45 +0800 Subject: benchmark the smi function --- benches/bench_sm.rs | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'benches') diff --git a/benches/bench_sm.rs b/benches/bench_sm.rs index 736397a..25dd3cc 100644 --- a/benches/bench_sm.rs +++ b/benches/bench_sm.rs @@ -7,7 +7,8 @@ use rand::{ thread_rng, }; -use sort::sm; +#[allow(unused_imports)] +use sort::{sm, smi}; fn bench_10(c: &mut Criterion) { let mut rng = thread_rng(); @@ -19,10 +20,10 @@ fn bench_10(c: &mut Criterion) { assert_eq!(input.len(), 10); - c.bench_function("sm", |b| { + c.bench_function("smi", |b| { b.iter(|| { let mut count = 0; - black_box(sm(input.as_slice(), &mut count)) + black_box(smi(input.as_slice(), &mut count)) }) }); } @@ -37,67 +38,67 @@ fn bench_20(c: &mut Criterion) { assert_eq!(input.len(), 20); - c.bench_function("sm", |b| { + c.bench_function("smi", |b| { b.iter(|| { let mut count = 0; - black_box(sm(input.as_slice(), &mut count)) + black_box(smi(input.as_slice(), &mut count)) }) }); } -fn bench_30(c: &mut Criterion) { +fn bench_40(c: &mut Criterion) { let mut rng = thread_rng(); let input = { let uniform = Uniform::new(-100.0f32, 100.0f32); - uniform.sample_iter(&mut rng).take(30).collect::>() + uniform.sample_iter(&mut rng).take(40).collect::>() }; - assert_eq!(input.len(), 30); + assert_eq!(input.len(), 40); - c.bench_function("sm", |b| { + c.bench_function("smi", |b| { b.iter(|| { let mut count = 0; - black_box(sm(input.as_slice(), &mut count)) + black_box(smi(input.as_slice(), &mut count)) }) }); } -fn bench_40(c: &mut Criterion) { +fn bench_80(c: &mut Criterion) { let mut rng = thread_rng(); let input = { let uniform = Uniform::new(-100.0f32, 100.0f32); - uniform.sample_iter(&mut rng).take(40).collect::>() + uniform.sample_iter(&mut rng).take(80).collect::>() }; - assert_eq!(input.len(), 40); + assert_eq!(input.len(), 80); - c.bench_function("sm", |b| { + c.bench_function("smi", |b| { b.iter(|| { let mut count = 0; - black_box(sm(input.as_slice(), &mut count)) + black_box(smi(input.as_slice(), &mut count)) }) }); } -fn bench_50(c: &mut Criterion) { +fn bench_160(c: &mut Criterion) { let mut rng = thread_rng(); let input = { let uniform = Uniform::new(-100.0f32, 100.0f32); - uniform.sample_iter(&mut rng).take(50).collect::>() + uniform.sample_iter(&mut rng).take(160).collect::>() }; - assert_eq!(input.len(), 50); + assert_eq!(input.len(), 160); - c.bench_function("sm", |b| { + c.bench_function("smi", |b| { b.iter(|| { let mut count = 0; - black_box(sm(input.as_slice(), &mut count)) + black_box(smi(input.as_slice(), &mut count)) }) }); } -criterion_group!(benches, bench_10, bench_20, bench_30, bench_40, bench_50); +criterion_group!(benches, bench_10, bench_20, bench_40, bench_80, bench_160); criterion_main!(benches); -- cgit v1.2.3-18-g5258