Skip to content

Commit

Permalink
chore: test running benchmarks in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Mar 20, 2024
1 parent 77f0381 commit ed805b0
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 32 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Benchmark
on:
pull_request:
push:
branches:
- master

# This will cancel previous runs when a branch or PR is updated
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref || github.run_id }}
cancel-in-progress: true

jobs:
run-benchmark:
name: Run benchmarks
runs-on: ubuntu-22.04
timeout-minutes: 30

steps:
- uses: actions/checkout@v4
- uses: boa-dev/criterion-compare-action@v3
with:
# Optional. Compare only this package
package: "nargo_cli"
# Optional. Compare only this benchmark target
benchName: "criterion"
7 changes: 7 additions & 0 deletions test_programs/execution_success/blake2s/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "blake2s"
type = "bin"
authors = [""]
compiler_version = ">=0.22.0"

[dependencies]
37 changes: 37 additions & 0 deletions test_programs/execution_success/blake2s/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# hello as bytes
# https://toolkitbay.com/tkb/tool/BLAKE2s_256
x = [104, 101, 108, 108, 111]
result = [
0x19,
0x21,
0x3b,
0xac,
0xc5,
0x8d,
0xee,
0x6d,
0xbd,
0xe3,
0xce,
0xb9,
0xa4,
0x7c,
0xbb,
0x33,
0x0b,
0x3d,
0x86,
0xf8,
0xcc,
0xa8,
0x99,
0x7e,
0xb0,
0x0b,
0xe4,
0x56,
0xf1,
0x40,
0xca,
0x25,
]
6 changes: 6 additions & 0 deletions test_programs/execution_success/blake2s/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use dep::std;

fn main(x: [u8; 5], result: [u8; 32]) {
let digest = std::hash::blake2s(x);
assert(digest == result);
}
4 changes: 0 additions & 4 deletions tooling/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,5 @@ test-binary = "3.0.2"
name = "criterion"
harness = false

[[bench]]
name = "iai"
harness = false

[features]
codegen-docs = ["dep:clap-markdown"]
7 changes: 6 additions & 1 deletion tooling/nargo_cli/benches/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ criterion_group! {
config = Criterion::default().sample_size(10).measurement_time(Duration::from_secs(20)).with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
targets = criterion_selected_tests_prove
}
criterion_main!(execution_benches, prove_benches);
criterion_group! {
name = prove_benches;
config = Criterion::default().sample_size(20).measurement_time(Duration::from_secs(20)).with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
targets = criterion_selected_tests_prove
}
criterion_main!(execution_benches, prove_execution_benches, prove_benches);
25 changes: 0 additions & 25 deletions tooling/nargo_cli/benches/iai.rs

This file was deleted.

24 changes: 22 additions & 2 deletions tooling/nargo_cli/benches/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
use std::path::PathBuf;

const BLACKBOX_FUNCTIONS: &[&str] = &[
"blake2s",
"blake3",
"bit_and",
"ecdsa_secp256k1",
"ecdsa_secp256r1",
"keccak256",
"pedersen_commitment",
"pedersen_hash",
"scalar_mul",
"schnorr",
"xor",
];

const CRYPTOGRAPHIC_PRIMITIVES: &[&str] =
&["eddsa", "poseidon_bn254_hash", "merkle_insert", "sha256"];

const RECURSION: &[&str] = &["double_verify_proof", "double_verify_nested_proof"];

#[allow(unused)]
fn get_selected_tests() -> Vec<PathBuf> {
let manifest_dir = match std::env::var("CARGO_MANIFEST_DIR") {
Expand All @@ -14,6 +33,7 @@ fn get_selected_tests() -> Vec<PathBuf> {
.join("test_programs")
.join("execution_success");

let selected_tests = vec!["struct", "eddsa", "regression"];
selected_tests.into_iter().map(|t| test_dir.join(t)).collect()
let selected_tests = BLACKBOX_FUNCTIONS.iter().chain(CRYPTOGRAPHIC_PRIMITIVES).chain(RECURSION);

selected_tests.map(|t| test_dir.join(t)).collect()
}

0 comments on commit ed805b0

Please sign in to comment.