diff --git a/.github/workflows/benchmark-master.yaml b/.github/workflows/benchmark-master.yaml index dae38f30c7..0764ed7db4 100644 --- a/.github/workflows/benchmark-master.yaml +++ b/.github/workflows/benchmark-master.yaml @@ -26,4 +26,4 @@ jobs: --branch master \ --testbed ubuntu-latest \ --adapter rust_criterion \ - nix develop --command cargo bench --package nickel-lang-core --bench numeric + nix develop --command cargo bench --package nickel-lang-core --features=benchmark-ci --bench numeric --bench arrays diff --git a/.github/workflows/benchmark-pr.yaml b/.github/workflows/benchmark-pr.yaml index 973f918caa..92db0cc2af 100644 --- a/.github/workflows/benchmark-pr.yaml +++ b/.github/workflows/benchmark-pr.yaml @@ -31,7 +31,7 @@ jobs: nix_path: "nixpkgs=channel:nixos-unstable" - name: run benchmarks run: | - nix develop --command cargo bench --package nickel-lang-core --bench numeric > criterion-output.txt + nix develop --command cargo bench --package nickel-lang-core --features=benchmark-ci --bench numeric --bench arrays > criterion-output.txt - name: upload results uses: actions/upload-artifact@v4 with: diff --git a/core/Cargo.toml b/core/Cargo.toml index 1661c2528c..3b91f85394 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -28,6 +28,7 @@ format = ["dep:topiary-core", "dep:topiary-queries", "dep:tree-sitter-nickel"] metrics = ["dep:metrics"] nix-experimental = [ "dep:cxx", "dep:cxx-build", "dep:pkg-config" ] spanned-deser = ["dep:serde-untagged"] +benchmark-ci = [] [build-dependencies] lalrpop.workspace = true diff --git a/core/benches/arrays.rs b/core/benches/arrays.rs index 9c8d36bf83..6634f48ec5 100644 --- a/core/benches/arrays.rs +++ b/core/benches/arrays.rs @@ -1,3 +1,5 @@ +#![cfg_attr(feature = "benchmark-ci", allow(unused_imports))] + use std::rc::Rc; use criterion::criterion_main; @@ -9,6 +11,7 @@ use nickel_lang_utils::{bench::criterion_config, bench::EvalMode, ncl_bench_grou use pretty::{BoxAllocator, DocBuilder, Pretty}; /// Generates a pseaudo-random Nickel array as a string. +#[cfg(not(feature = "benchmark-ci"))] fn ncl_random_array(len: usize) -> String { let m = 2_u64.pow(32); let a = 1664525; @@ -32,6 +35,7 @@ fn ncl_random_array(len: usize) -> String { String::from_utf8(out).unwrap() } +#[cfg(not(feature = "benchmark-ci"))] ncl_bench_group! { name = benches; config = criterion_config(); @@ -168,4 +172,63 @@ config = criterion_config(); eval_mode = EvalMode::DeepSeq, } } + +#[cfg(feature = "benchmark-ci")] +ncl_bench_group! { +name = benches; +config = criterion_config(); +{ + name = "foldr strings 50", + path = "arrays/fold", + subtest = "right.strings", + args = (50), + }, { + name = "foldr strings 500", + path = "arrays/fold", + subtest = "right.strings", + args = (500), + }, { + name = "foldl arrays 50", + path = "arrays/fold", + subtest = "left.arrays", + args = (50), + }, { + name = "foldl arrays 500", + path = "arrays/fold", + subtest = "left.arrays", + args = (500), + }, { + name = "generate normal 50", + path = "arrays/generate", + subtest = "checked", + args = (50), + }, { + name = "generate normal 250", + path = "arrays/generate", + subtest = "checked", + // Most other benchmarks have a factor of 10 between + // the small and large sizes, but this one is slow so + // use a factor of 5. + args = (250), + }, { + name = "generate normal unchecked 200", + path = "arrays/generate", + subtest = "unchecked", + args = (200), + }, { + name = "generate normal unchecked 1000", + path = "arrays/generate", + subtest = "unchecked", + args = (1000), + }, { + name = "pipe normal 20", + path = "arrays/pipe", + args = (20), + }, { + name = "pipe normal 200", + path = "arrays/pipe", + args = (200), + }, +} + criterion_main!(benches); diff --git a/core/benches/arrays/sum.ncl b/core/benches/arrays/sum.ncl index 7b66cc5887..180ead325b 100644 --- a/core/benches/arrays/sum.ncl +++ b/core/benches/arrays/sum.ncl @@ -1,9 +1,8 @@ let rec sum | Array Number -> Number - = fun xs => - if std.array.length xs == 0 then - 0 - else - std.array.first xs + sum (std.array.drop_first xs) + = match { + [] => 0, + [x, ..xs] => x + sum xs, + } in { run = fun n => std.array.generate (fun x => x + 1) n |> sum