Port benchmarks to Criterion.
With Criterion the benchmarks work on stable Rust, too.
Change-Id: I0d460ffd265e82a21c625c41930dcce7521e34af
diff --git a/benches/benchmarks.rs b/benches/benchmarks.rs
index ec5e75c..6c0148b 100644
--- a/benches/benchmarks.rs
+++ b/benches/benchmarks.rs
@@ -1,19 +1,19 @@
#![cfg(test)]
-#![feature(test)]
-#![feature(slice_fill)]
+extern crate criterion;
+extern crate criterion_bencher_compat;
extern crate num;
-extern crate test;
use rust_samples::swapper::{
CAllocaSwapper, CLoopSwapper, CMallocSwapper, LoopSwapper, PtrSwapper, Swapper,
};
+use criterion::measurement::WallTime;
+use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion};
use heapless::consts::{U10, U100, U1000, U10000, U100000, U1000000};
use num::{one, zero, Num};
-use test::{black_box, Bencher};
-fn bench_swap<S, T, N>(b: &mut Bencher)
+fn bench_swap<S, T, N>(b: &mut Bencher<WallTime>)
where
S: Swapper,
N: heapless::ArrayLength<T>,
@@ -62,152 +62,217 @@
type BenchInt = u8;
-#[bench]
-fn bench_swap_loop_len_10(b: &mut Bencher) {
- bench_swap::<LoopSwapper, BenchInt, U10>(b);
+fn bench_swap_loop_len_10(c: &mut Criterion) {
+ c.bench_function("swap_loop_len_10", |b| {
+ bench_swap::<LoopSwapper, BenchInt, U10>(b)
+ });
}
-#[bench]
-fn bench_swap_loop_len_100(b: &mut Bencher) {
- bench_swap::<LoopSwapper, BenchInt, U100>(b);
+fn bench_swap_loop_len_100(c: &mut Criterion) {
+ c.bench_function("swap_loop_len_100", |b| {
+ bench_swap::<LoopSwapper, BenchInt, U100>(b)
+ });
}
-#[bench]
-fn bench_swap_loop_len_1000(b: &mut Bencher) {
- bench_swap::<LoopSwapper, BenchInt, U1000>(b);
+fn bench_swap_loop_len_1000(c: &mut Criterion) {
+ c.bench_function("swap_loop_len_1000", |b| {
+ bench_swap::<LoopSwapper, BenchInt, U1000>(b)
+ });
}
-#[bench]
-fn bench_swap_loop_len_10000(b: &mut Bencher) {
- bench_swap::<LoopSwapper, BenchInt, U10000>(b);
+fn bench_swap_loop_len_10000(c: &mut Criterion) {
+ c.bench_function("swap_loop_len_10000", |b| {
+ bench_swap::<LoopSwapper, BenchInt, U10000>(b)
+ });
}
-#[bench]
-fn bench_swap_loop_len_100000(b: &mut Bencher) {
- bench_swap::<LoopSwapper, BenchInt, U100000>(b);
+fn bench_swap_loop_len_100000(c: &mut Criterion) {
+ c.bench_function("swap_loop_len_100000", |b| {
+ bench_swap::<LoopSwapper, BenchInt, U100000>(b)
+ });
}
-#[bench]
-fn bench_swap_loop_len_1000000(b: &mut Bencher) {
- bench_swap::<LoopSwapper, BenchInt, U1000000>(b);
+fn bench_swap_loop_len_1000000(c: &mut Criterion) {
+ c.bench_function("swap_loop_len_1000000", |b| {
+ bench_swap::<LoopSwapper, BenchInt, U1000000>(b)
+ });
}
-#[bench]
-fn bench_swap_ptrswap_len_10(b: &mut Bencher) {
- bench_swap::<PtrSwapper, BenchInt, U10>(b);
+fn bench_swap_ptrswap_len_10(c: &mut Criterion) {
+ c.bench_function("swap_ptrswap_len_10", |b| {
+ bench_swap::<PtrSwapper, BenchInt, U10>(b)
+ });
}
-#[bench]
-fn bench_swap_ptrswap_len_100(b: &mut Bencher) {
- bench_swap::<PtrSwapper, BenchInt, U100>(b);
+fn bench_swap_ptrswap_len_100(c: &mut Criterion) {
+ c.bench_function("swap_ptrswap_len_100", |b| {
+ bench_swap::<PtrSwapper, BenchInt, U100>(b)
+ });
}
-#[bench]
-fn bench_swap_ptrswap_len_1000(b: &mut Bencher) {
- bench_swap::<PtrSwapper, BenchInt, U1000>(b);
+fn bench_swap_ptrswap_len_1000(c: &mut Criterion) {
+ c.bench_function("swap_ptrswap_len_1000", |b| {
+ bench_swap::<PtrSwapper, BenchInt, U1000>(b)
+ });
}
-#[bench]
-fn bench_swap_ptrswap_len_10000(b: &mut Bencher) {
- bench_swap::<PtrSwapper, BenchInt, U10000>(b);
+fn bench_swap_ptrswap_len_10000(c: &mut Criterion) {
+ c.bench_function("swap_ptrswap_len_10000", |b| {
+ bench_swap::<PtrSwapper, BenchInt, U10000>(b)
+ });
}
-#[bench]
-fn bench_swap_ptrswap_len_100000(b: &mut Bencher) {
- bench_swap::<PtrSwapper, BenchInt, U100000>(b);
+fn bench_swap_ptrswap_len_100000(c: &mut Criterion) {
+ c.bench_function("swap_ptrswap_len_100000", |b| {
+ bench_swap::<PtrSwapper, BenchInt, U100000>(b)
+ });
}
-#[bench]
-fn bench_swap_ptrswap_len_1000000(b: &mut Bencher) {
- bench_swap::<PtrSwapper, BenchInt, U1000000>(b);
+fn bench_swap_ptrswap_len_1000000(c: &mut Criterion) {
+ c.bench_function("swap_ptrswap_len_1000000", |b| {
+ bench_swap::<PtrSwapper, BenchInt, U1000000>(b)
+ });
}
-#[bench]
-fn bench_cswap_loop_len_10(b: &mut Bencher) {
- bench_swap::<CLoopSwapper, BenchInt, U10>(b);
+fn bench_cswap_loop_len_10(c: &mut Criterion) {
+ c.bench_function("cswap_loop_len_10", |b| {
+ bench_swap::<CLoopSwapper, BenchInt, U10>(b)
+ });
}
-#[bench]
-fn bench_cswap_loop_len_100(b: &mut Bencher) {
- bench_swap::<CLoopSwapper, BenchInt, U100>(b);
+fn bench_cswap_loop_len_100(c: &mut Criterion) {
+ c.bench_function("cswap_loop_len_100", |b| {
+ bench_swap::<CLoopSwapper, BenchInt, U100>(b)
+ });
}
-#[bench]
-fn bench_cswap_loop_len_1000(b: &mut Bencher) {
- bench_swap::<CLoopSwapper, BenchInt, U1000>(b);
+fn bench_cswap_loop_len_1000(c: &mut Criterion) {
+ c.bench_function("cswap_loop_len_1000", |b| {
+ bench_swap::<CLoopSwapper, BenchInt, U1000>(b)
+ });
}
-#[bench]
-fn bench_cswap_loop_len_10000(b: &mut Bencher) {
- bench_swap::<CLoopSwapper, BenchInt, U10000>(b);
+fn bench_cswap_loop_len_10000(c: &mut Criterion) {
+ c.bench_function("cswap_loop_len_10000", |b| {
+ bench_swap::<CLoopSwapper, BenchInt, U10000>(b)
+ });
}
-#[bench]
-fn bench_cswap_loop_len_100000(b: &mut Bencher) {
- bench_swap::<CLoopSwapper, BenchInt, U100000>(b);
+fn bench_cswap_loop_len_100000(c: &mut Criterion) {
+ c.bench_function("cswap_loop_len_100000", |b| {
+ bench_swap::<CLoopSwapper, BenchInt, U100000>(b)
+ });
}
-#[bench]
-fn bench_cswap_loop_len_1000000(b: &mut Bencher) {
- bench_swap::<CLoopSwapper, BenchInt, U1000000>(b);
+fn bench_cswap_loop_len_1000000(c: &mut Criterion) {
+ c.bench_function("cswap_loop_len_1000000", |b| {
+ bench_swap::<CLoopSwapper, BenchInt, U1000000>(b)
+ });
}
-#[bench]
-fn bench_cswap_alloca_len_10(b: &mut Bencher) {
- bench_swap::<CAllocaSwapper, BenchInt, U10>(b);
+fn bench_cswap_alloca_len_10(c: &mut Criterion) {
+ c.bench_function("cswap_alloca_len_10", |b| {
+ bench_swap::<CAllocaSwapper, BenchInt, U10>(b)
+ });
}
-#[bench]
-fn bench_cswap_alloca_len_100(b: &mut Bencher) {
- bench_swap::<CAllocaSwapper, BenchInt, U100>(b);
+fn bench_cswap_alloca_len_100(c: &mut Criterion) {
+ c.bench_function("cswap_alloca_len_100", |b| {
+ bench_swap::<CAllocaSwapper, BenchInt, U100>(b)
+ });
}
-#[bench]
-fn bench_cswap_alloca_len_1000(b: &mut Bencher) {
- bench_swap::<CAllocaSwapper, BenchInt, U1000>(b);
+fn bench_cswap_alloca_len_1000(c: &mut Criterion) {
+ c.bench_function("cswap_alloca_len_1000", |b| {
+ bench_swap::<CAllocaSwapper, BenchInt, U1000>(b)
+ });
}
-#[bench]
-fn bench_cswap_alloca_len_10000(b: &mut Bencher) {
- bench_swap::<CAllocaSwapper, BenchInt, U10000>(b);
+fn bench_cswap_alloca_len_10000(c: &mut Criterion) {
+ c.bench_function("cswap_alloca_len_10000", |b| {
+ bench_swap::<CAllocaSwapper, BenchInt, U10000>(b)
+ });
}
-#[bench]
-fn bench_cswap_alloca_len_100000(b: &mut Bencher) {
- bench_swap::<CAllocaSwapper, BenchInt, U100000>(b);
+fn bench_cswap_alloca_len_100000(c: &mut Criterion) {
+ c.bench_function("cswap_alloca_len_100000", |b| {
+ bench_swap::<CAllocaSwapper, BenchInt, U100000>(b)
+ });
}
-#[bench]
-fn bench_cswap_alloca_len_1000000(b: &mut Bencher) {
- bench_swap::<CAllocaSwapper, BenchInt, U1000000>(b);
+fn bench_cswap_alloca_len_1000000(c: &mut Criterion) {
+ c.bench_function("cswap_alloca_len_1000000", |b| {
+ bench_swap::<CAllocaSwapper, BenchInt, U1000000>(b)
+ });
}
-#[bench]
-fn bench_cswap_malloc_len_10(b: &mut Bencher) {
- bench_swap::<CMallocSwapper, BenchInt, U10>(b);
+fn bench_cswap_malloc_len_10(c: &mut Criterion) {
+ c.bench_function("cswap_malloc_len_10", |b| {
+ bench_swap::<CMallocSwapper, BenchInt, U10>(b)
+ });
}
-#[bench]
-fn bench_cswap_malloc_len_100(b: &mut Bencher) {
- bench_swap::<CMallocSwapper, BenchInt, U100>(b);
+fn bench_cswap_malloc_len_100(c: &mut Criterion) {
+ c.bench_function("cswap_malloc_len_100", |b| {
+ bench_swap::<CMallocSwapper, BenchInt, U100>(b)
+ });
}
-#[bench]
-fn bench_cswap_malloc_len_1000(b: &mut Bencher) {
- bench_swap::<CMallocSwapper, BenchInt, U1000>(b);
+fn bench_cswap_malloc_len_1000(c: &mut Criterion) {
+ c.bench_function("cswap_malloc_len_1000", |b| {
+ bench_swap::<CMallocSwapper, BenchInt, U1000>(b)
+ });
}
-#[bench]
-fn bench_cswap_malloc_len_10000(b: &mut Bencher) {
- bench_swap::<CMallocSwapper, BenchInt, U10000>(b);
+fn bench_cswap_malloc_len_10000(c: &mut Criterion) {
+ c.bench_function("cswap_malloc_len_10000", |b| {
+ bench_swap::<CMallocSwapper, BenchInt, U10000>(b)
+ });
}
-#[bench]
-fn bench_cswap_malloc_len_100000(b: &mut Bencher) {
- bench_swap::<CMallocSwapper, BenchInt, U100000>(b);
+fn bench_cswap_malloc_len_100000(c: &mut Criterion) {
+ c.bench_function("cswap_malloc_len_100000", |b| {
+ bench_swap::<CMallocSwapper, BenchInt, U100000>(b)
+ });
}
-#[bench]
-fn bench_cswap_malloc_len_1000000(b: &mut Bencher) {
- bench_swap::<CMallocSwapper, BenchInt, U1000000>(b);
+fn bench_cswap_malloc_len_1000000(c: &mut Criterion) {
+ c.bench_function("cswap_malloc_len_1000000", |b| {
+ bench_swap::<CMallocSwapper, BenchInt, U1000000>(b)
+ });
}
+
+criterion_group!(
+ benches,
+ bench_swap_loop_len_10,
+ bench_swap_loop_len_100,
+ bench_swap_loop_len_1000,
+ bench_swap_loop_len_10000,
+ bench_swap_loop_len_100000,
+ bench_swap_loop_len_1000000,
+ bench_swap_ptrswap_len_10,
+ bench_swap_ptrswap_len_100,
+ bench_swap_ptrswap_len_1000,
+ bench_swap_ptrswap_len_10000,
+ bench_swap_ptrswap_len_100000,
+ bench_swap_ptrswap_len_1000000,
+ bench_cswap_loop_len_10,
+ bench_cswap_loop_len_100,
+ bench_cswap_loop_len_1000,
+ bench_cswap_loop_len_10000,
+ bench_cswap_loop_len_100000,
+ bench_cswap_loop_len_1000000,
+ bench_cswap_alloca_len_10,
+ bench_cswap_alloca_len_100,
+ bench_cswap_alloca_len_1000,
+ bench_cswap_alloca_len_10000,
+ bench_cswap_alloca_len_100000,
+ bench_cswap_alloca_len_1000000,
+ bench_cswap_malloc_len_10,
+ bench_cswap_malloc_len_100,
+ bench_cswap_malloc_len_1000,
+ bench_cswap_malloc_len_10000,
+ bench_cswap_malloc_len_100000,
+ bench_cswap_malloc_len_1000000
+);
+criterion_main!(benches);