Skip to content

Commit

Permalink
Fix criterion-cycles-per-byte compilation error on non-x86_64 platforms.
Browse files Browse the repository at this point in the history
  • Loading branch information
orf committed Aug 25, 2023
1 parent 9eab2f0 commit f0347f0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 68 deletions.
83 changes: 17 additions & 66 deletions native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion native/libcst/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ libcst_derive = { path = "../libcst_derive" }

[dev-dependencies]
criterion = { version = "0.4.0", features = ["html_reports"] }
criterion-cycles-per-byte = "0.1"
difference = "2.0.0"

[target.'cfg(target_arch = "x86_64")'.dev-dependencies]
criterion-cycles-per-byte = "0.1"

[[bench]]
name = "parser_benchmark"
harness = false
14 changes: 13 additions & 1 deletion native/libcst/benches/parser_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
use criterion::{
black_box, criterion_group, criterion_main, measurement::Measurement, BatchSize, Criterion,
};
#[cfg(target_arch = "x86_64")]
use criterion_cycles_per_byte::CyclesPerByte;
use itertools::Itertools;
use libcst_native::{
Expand Down Expand Up @@ -118,9 +119,20 @@ pub fn parse_into_cst_benchmarks<T: Measurement>(c: &mut Criterion<T>) {
group.finish();
}

#[cfg(target_arch = "x86_64")]
fn get_config() -> Criterion {
// criterion_cycles_per_byte is only supported on x86
Criterion::default().config.with_measurement(CyclesPerByte)
}

#[cfg(not(target_arch = "x86_64"))]
fn get_config() -> Criterion {
Criterion::default()
}

criterion_group!(
name=benches;
config = Criterion::default().with_measurement(CyclesPerByte);
config=get_config();
targets=parser_benchmarks, codegen_benchmarks, inflate_benchmarks, tokenize_benchmarks, parse_into_cst_benchmarks
);
criterion_main!(benches);

0 comments on commit f0347f0

Please sign in to comment.