Skip to content

Commit

Permalink
Fix benchmarks on Windows (#2024)
Browse files Browse the repository at this point in the history
  • Loading branch information
cydparser authored Aug 8, 2024
1 parent 2754065 commit e333308
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ strsim = "0.10.0"
pretty_assertions.workspace = true
assert_matches.workspace = true
criterion.workspace = true
pprof = { workspace = true, features = ["criterion", "flamegraph"] }
nickel-lang-utils.workspace = true
similar.workspace = true
test-generator.workspace = true
Expand Down
7 changes: 3 additions & 4 deletions core/benches/arrays.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::rc::Rc;

use criterion::{criterion_main, Criterion};
use criterion::criterion_main;
use nickel_lang_core::term::{
array::{Array, ArrayAttrs},
Number, RichTerm, Term,
};
use nickel_lang_utils::{bench::EvalMode, ncl_bench_group};
use pprof::criterion::{Output, PProfProfiler};
use nickel_lang_utils::{bench::criterion_config, bench::EvalMode, ncl_bench_group};
use pretty::{BoxAllocator, DocBuilder, Pretty};

/// Generates a pseaudo-random Nickel array as a string.
Expand Down Expand Up @@ -35,7 +34,7 @@ fn ncl_random_array(len: usize) -> String {

ncl_bench_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = criterion_config();
{
name = "foldr strings 50",
path = "arrays/fold",
Expand Down
7 changes: 3 additions & 4 deletions core/benches/functions.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use criterion::{criterion_main, Criterion};
use nickel_lang_utils::ncl_bench_group;
use pprof::criterion::{Output, PProfProfiler};
use criterion::criterion_main;
use nickel_lang_utils::{bench::criterion_config, ncl_bench_group};

ncl_bench_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = criterion_config();
{
name = "church 3",
path = "functions/church",
Expand Down
7 changes: 3 additions & 4 deletions core/benches/mantis.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use criterion::{criterion_main, Criterion};
use nickel_lang_utils::{bench::EvalMode, ncl_bench_group};
use pprof::criterion::{Output, PProfProfiler};
use criterion::criterion_main;
use nickel_lang_utils::{bench::criterion_config, bench::EvalMode, ncl_bench_group};

ncl_bench_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = criterion_config();
{
name = "mantis",
path = "mantis/run",
Expand Down
7 changes: 3 additions & 4 deletions core/benches/numeric.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use criterion::{criterion_main, Criterion};
use nickel_lang_utils::ncl_bench_group;
use pprof::criterion::{Output, PProfProfiler};
use criterion::criterion_main;
use nickel_lang_utils::{bench::criterion_config, ncl_bench_group};

ncl_bench_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = criterion_config();
{
name = "fibonacci 10",
path = "numeric/fibonacci",
Expand Down
7 changes: 3 additions & 4 deletions core/benches/records.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use criterion::{criterion_main, Criterion};
use nickel_lang_utils::{bench::EvalMode, ncl_bench_group};
use pprof::criterion::{Output, PProfProfiler};
use criterion::criterion_main;
use nickel_lang_utils::{bench::criterion_config, bench::EvalMode, ncl_bench_group};

ncl_bench_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = criterion_config();
{
name = "countLetters",
path = "records/countLetters",
Expand Down
7 changes: 3 additions & 4 deletions core/benches/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use criterion::{criterion_main, Criterion};
use nickel_lang_utils::ncl_bench_group;
use pprof::criterion::{Output, PProfProfiler};
use criterion::criterion_main;
use nickel_lang_utils::{bench::criterion_config, ncl_bench_group};

ncl_bench_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = criterion_config();
{
name = "round_trip",
path = "serialization/main",
Expand Down
4 changes: 2 additions & 2 deletions core/benches/stdlib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use criterion::{criterion_group, criterion_main, Criterion};
use pprof::criterion::{Output, PProfProfiler};

use nickel_lang_core::cache::{Cache, ErrorTolerance};
use nickel_lang_utils::bench::criterion_config;

pub fn typecheck_stdlib(c: &mut Criterion) {
let mut cache = Cache::new(ErrorTolerance::Strict);
Expand All @@ -18,7 +18,7 @@ pub fn typecheck_stdlib(c: &mut Criterion) {

criterion_group!(
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = criterion_config();
targets = typecheck_stdlib
);
criterion_main!(benches);
7 changes: 3 additions & 4 deletions core/benches/typecheck-nixpkgs-lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use criterion::{criterion_main, Criterion};
use nickel_lang_utils::{bench::EvalMode, ncl_bench_group};
use pprof::criterion::{Output, PProfProfiler};
use criterion::criterion_main;
use nickel_lang_utils::{bench::criterion_config, bench::EvalMode, ncl_bench_group};

ncl_bench_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
config = criterion_config();
{
name = "nixpkgs lists",
path = "nixpkgs/lists",
Expand Down
3 changes: 3 additions & 0 deletions utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ criterion.workspace = true
codespan.workspace = true
serde = { workspace = true, features = ["derive"] }
toml = { workspace = true, features = ["parse"] }

[target.'cfg(target_family = "unix")'.dependencies]
pprof = { workspace = true, features = ["criterion", "flamegraph"] }
23 changes: 18 additions & 5 deletions utils/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'b> Bench<'b> {

let field_path = self.subtest.map(|s| format!(".{s}")).unwrap_or_default();
let content = format!(
"(import \"{}\"){}.run {}",
"(import {:?}){}.run {}",
path.to_string_lossy(),
field_path,
self.args
Expand All @@ -86,13 +86,15 @@ impl<'b> Bench<'b> {
} else {
content
};
parse(&content).unwrap()
parse(&content).unwrap_or_else(|err| panic!("Failed parsing {path:?}: {err:?}"))
}

pub fn path(&self) -> PathBuf {
let mut path = PathBuf::from(self.base_dir);
path.push(format!("benches/{}.ncl", self.subpath));
path
PathBuf::from_iter([
self.base_dir,
"benches",
format!("{}.ncl", self.subpath).as_str(),
])
}
}

Expand Down Expand Up @@ -139,6 +141,17 @@ pub fn bench_terms<'r>(rts: Vec<Bench<'r>>) -> Box<dyn Fn(&mut Criterion) + 'r>
})
}

/// Create a `Criterion` config. Uses the `PProfProfiler` on Unix systems.
pub fn criterion_config() -> Criterion {
let config = Criterion::default();
#[cfg(target_family = "unix")]
let config = config.with_profiler(pprof::criterion::PProfProfiler::new(
100,
pprof::criterion::Output::Flamegraph(None),
));
config
}

#[macro_export]
macro_rules! ncl_bench {
{
Expand Down

0 comments on commit e333308

Please sign in to comment.