Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
Measure benchmark runtime in cycles per byte on x86
Browse files Browse the repository at this point in the history
  • Loading branch information
milkey-mouse committed Jun 30, 2020
1 parent 1496561 commit addaf8c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ version = "0.1.0"
authors = ["Heinz N. Gies <[email protected]>"]
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"
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
21 changes: 15 additions & 6 deletions benches/criterion_bench.rs
Original file line number Diff line number Diff line change
@@ -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<T: Measurement>(c: &mut Criterion<T>, 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);
Expand Down Expand Up @@ -47,5 +50,11 @@ fn bench_all<T: Measurement>(c: &mut Criterion<T>) {
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);

0 comments on commit addaf8c

Please sign in to comment.