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

Commit 903e2a2

Browse files
committed
Measure benchmark runtime in cycles per byte on x86
1 parent bec1eff commit 903e2a2

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
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 <heinz@licenser.net>"]
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: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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) {
@@ -50,5 +50,14 @@ fn bench_all<T: Measurement>(c: &mut Criterion<T>) {
5050
bench_file(c, "ascii_sample_ok", true);
5151
}
5252

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+
60+
#[cfg(not(all(any(target_arch = "x86_64", target_arch = "x86"), feature = "cpb")))]
5361
criterion_group!(benches, bench_all);
62+
5463
criterion_main!(benches);

0 commit comments

Comments
 (0)