Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds some array benchmarks to the ones tracked in CI #2067

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/benchmark-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/benchmark-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions core/benches/arrays.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(feature = "benchmark-ci", allow(unused_imports))]

use std::rc::Rc;

use criterion::criterion_main;
Expand All @@ -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;
Expand All @@ -32,6 +35,7 @@ fn ncl_random_array(len: usize) -> String {
String::from_utf8(out).unwrap()
}

#[cfg(not(feature = "benchmark-ci"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the whole ncl_bench_group! is gated behind the feature, is there a reason why we need to disable individual benchmark with a #[cfg(not(...))] as well ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without configuring out those things, CI failed with unused code warnings.

ncl_bench_group! {
name = benches;
config = criterion_config();
Expand Down Expand Up @@ -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);
9 changes: 4 additions & 5 deletions core/benches/arrays/sum.ncl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading