Skip to content

Commit

Permalink
gate the benchmark behind the bench feature that it uses (#8)
Browse files Browse the repository at this point in the history
* gate the benchmark behind the bench feature that it uses, so that 'cargo bench --no-default-features' doesn't have compilation errors

* Change cfg(bench) to feature bench

* Fixup clippy

---------

Co-authored-by: MarcusGrass <marcus.grass@protonmail.com>
  • Loading branch information
alexanderkjall and MarcusGrass committed Oct 5, 2023
1 parent b13eece commit 7e732a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tiny-bench/benches/benchmark.rs
@@ -1,13 +1,20 @@
#[cfg(feature = "bench")]
use std::time::Duration;
#[cfg(feature = "bench")]
use tiny_bench::{black_box, BenchmarkConfig};

fn main() {
#[cfg(feature = "bench")]
bench_test_one();
#[cfg(feature = "bench")]
bench_test_two();
#[cfg(feature = "bench")]
bench_test_three();
#[cfg(feature = "bench")]
bench_test_four();
}

#[cfg(feature = "bench")]
fn bench_test_one() {
tiny_bench::bench_labeled("test one", || {
let mut v: Vec<i32> = Vec::with_capacity(10_000);
Expand All @@ -22,6 +29,7 @@ fn bench_test_one() {
});
}

#[cfg(feature = "bench")]
fn bench_test_two() {
tiny_bench::bench_with_setup_labeled(
"test two",
Expand All @@ -43,10 +51,12 @@ fn bench_test_two() {
);
}

#[cfg(feature = "bench")]
fn bench_test_three() {
tiny_bench::bench_labeled("test three, empty", || {});
}

#[cfg(feature = "bench")]
fn bench_test_four() {
tiny_bench::bench_with_configuration_labeled(
"test four, max_it",
Expand Down
1 change: 1 addition & 0 deletions tiny-bench/src/output/analysis/criterion/mod.rs
Expand Up @@ -18,6 +18,7 @@ use std::time::Duration;
/// }
/// ```
#[allow(unsafe_code)]
#[allow(clippy::mem_forget)]
pub fn black_box<T>(dummy: T) -> T {
unsafe {
let ret = std::ptr::read_volatile(&dummy);
Expand Down

0 comments on commit 7e732a6

Please sign in to comment.