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

chore: test running benchmarks in CI #4604

Closed
wants to merge 10 commits into from
Closed
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
54 changes: 54 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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:
execute:
name: Run execution benchmarks
runs-on: ubuntu-22.04
timeout-minutes: 30

steps:
- uses: actions/checkout@v4

- uses: Swatinem/rust-cache@v2
with:
key: benchmarks

- run: cargo bench execute

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: execution-benchmarks
path: ./target/criterion
retention-days: 10

prove:
name: Run proving benchmarks
runs-on: ubuntu-22.04
timeout-minutes: 60

steps:
- uses: actions/checkout@v4

- uses: Swatinem/rust-cache@v2
with:
key: benchmarks

- run: cargo bench prove

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: proving-benchmarks
path: ./target/criterion
retention-days: 10
2 changes: 1 addition & 1 deletion .github/workflows/test-rust-workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
build-test-artifacts:
name: Build test artifacts
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 60

steps:
- name: Checkout
Expand Down
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: 2 additions & 2 deletions tooling/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ iai = "0.1.1"
test-binary = "3.0.2"

[[bench]]
name = "criterion"
name = "execution"
harness = false

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

[features]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@ macro_rules! criterion_command {
};
}
criterion_command!(execution, "execute");
criterion_command!(prove, "prove");

criterion_group! {
name = execution_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_execution
}
criterion_group! {
name = prove_benches;
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_main!(execution_benches);
25 changes: 0 additions & 25 deletions tooling/nargo_cli/benches/iai.rs

This file was deleted.

36 changes: 36 additions & 0 deletions tooling/nargo_cli/benches/proof_generation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! Select representative tests to bench with criterion
use assert_cmd::prelude::{CommandCargoExt, OutputAssertExt};
use criterion::{criterion_group, criterion_main, Criterion};

use paste::paste;
use pprof::criterion::{Output, PProfProfiler};
use std::{process::Command, time::Duration};
include!("./utils.rs");

macro_rules! criterion_command {
($command_name:tt, $command_string:expr) => {
paste! {
fn [<criterion_selected_tests_ $command_name>](c: &mut Criterion) {
let test_program_dirs = get_selected_tests();
for test_program_dir in test_program_dirs {
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("--program-dir").arg(&test_program_dir);
cmd.arg($command_string);
cmd.arg("--force");

let benchmark_name = format!("{}_{}", test_program_dir.file_name().unwrap().to_str().unwrap(), $command_string);
c.bench_function(&benchmark_name, |b| {
b.iter(|| cmd.assert().success())
});
}
}
}
};
}
criterion_command!(prove, "prove");
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!(prove_benches);
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()
}
Loading