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

Commit addaf8c

Browse files
committed
Measure benchmark runtime in cycles per byte on x86
1 parent 1496561 commit addaf8c

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ version = "0.1.0"
44
authors = ["Heinz N. Gies <[email protected]>"]
55
edition = "2018"
66

7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8-
7+
[features]
8+
default = ["cpb"]
9+
cpb = []
910

1011
[dev-dependencies]
1112
proptest = "0.10"
1213
criterion = "0.3"
1314
mimalloc = "0.1"
1415
core_affinity = "*"
1516

17+
[target.'cfg(any(target_arch = "x86_64", target_arch = "x86"))'.dev-dependencies]
18+
criterion-cycles-per-byte = "0.1"
19+
1620
[[bench]]
1721
name = "criterion_bench"
1822
harness = false

benches/criterion_bench.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
extern crate core_affinity;
2-
#[macro_use]
3-
extern crate criterion;
4-
51
use mimalloc::MiMalloc;
62
#[global_allocator]
73
static GLOBAL: MiMalloc = MiMalloc;
84

9-
use criterion::{measurement::Measurement, Criterion, Throughput};
5+
use criterion::{criterion_group, criterion_main, measurement::Measurement, Criterion, Throughput};
6+
7+
#[cfg(all(any(target_arch = "x86_64", target_arch = "x86"), feature = "cpb"))]
8+
use criterion_cycles_per_byte::CyclesPerByte;
9+
1010
use std::{fs, str};
1111

1212
fn bench_file<T: Measurement>(c: &mut Criterion<T>, name: &str, is_valid: bool) {
13+
let core_ids = core_affinity::get_core_ids().unwrap();
14+
core_affinity::set_for_current(core_ids[0]);
15+
1316
let buf = fs::read(format!("data/{}.data", name)).unwrap();
1417

1518
let mut group = c.benchmark_group(name);
@@ -47,5 +50,11 @@ fn bench_all<T: Measurement>(c: &mut Criterion<T>) {
4750
bench_file(c, "ascii_sample_ok", true);
4851
}
4952

50-
criterion_group!(benches, bench_all);
53+
#[cfg(all(any(target_arch = "x86_64", target_arch = "x86"), feature = "cpb"))]
54+
criterion_group! {
55+
name = benches;
56+
config = Criterion::default().with_measurement(CyclesPerByte);
57+
targets = bench_all
58+
}
59+
5160
criterion_main!(benches);

0 commit comments

Comments
 (0)