From addaf8cfd639daf0a89e63fbea48b7f93cd917ce Mon Sep 17 00:00:00 2001 From: Milkey Mouse Date: Mon, 29 Jun 2020 21:54:52 -0700 Subject: [PATCH] Measure benchmark runtime in cycles per byte on x86 --- Cargo.toml | 8 ++++++-- benches/criterion_bench.rs | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 68542d1..647581d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,9 @@ version = "0.1.0" authors = ["Heinz N. Gies "] edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - +[features] +default = ["cpb"] +cpb = [] [dev-dependencies] proptest = "0.10" @@ -13,6 +14,9 @@ criterion = "0.3" mimalloc = "0.1" core_affinity = "*" +[target.'cfg(any(target_arch = "x86_64", target_arch = "x86"))'.dev-dependencies] +criterion-cycles-per-byte = "0.1" + [[bench]] name = "criterion_bench" harness = false diff --git a/benches/criterion_bench.rs b/benches/criterion_bench.rs index 56198a8..9234066 100644 --- a/benches/criterion_bench.rs +++ b/benches/criterion_bench.rs @@ -1,15 +1,18 @@ -extern crate core_affinity; -#[macro_use] -extern crate criterion; - use mimalloc::MiMalloc; #[global_allocator] static GLOBAL: MiMalloc = MiMalloc; -use criterion::{measurement::Measurement, Criterion, Throughput}; +use criterion::{criterion_group, criterion_main, measurement::Measurement, Criterion, Throughput}; + +#[cfg(all(any(target_arch = "x86_64", target_arch = "x86"), feature = "cpb"))] +use criterion_cycles_per_byte::CyclesPerByte; + use std::{fs, str}; fn bench_file(c: &mut Criterion, name: &str, is_valid: bool) { + let core_ids = core_affinity::get_core_ids().unwrap(); + core_affinity::set_for_current(core_ids[0]); + let buf = fs::read(format!("data/{}.data", name)).unwrap(); let mut group = c.benchmark_group(name); @@ -47,5 +50,11 @@ fn bench_all(c: &mut Criterion) { bench_file(c, "ascii_sample_ok", true); } -criterion_group!(benches, bench_all); +#[cfg(all(any(target_arch = "x86_64", target_arch = "x86"), feature = "cpb"))] +criterion_group! { + name = benches; + config = Criterion::default().with_measurement(CyclesPerByte); + targets = bench_all +} + criterion_main!(benches);