Skip to content

Commit

Permalink
Merge pull request #301 from PatStiles/feat/callgrind
Browse files Browse the repository at this point in the history
feat(bench): Add callgrind benches for jolt-core
  • Loading branch information
moodlezoup authored Apr 17, 2024
2 parents bf31bd0 + 7ef04bd commit 6f857f5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
5 changes: 5 additions & 0 deletions jolt-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ tracing-chrome = "0.7.1"
tracing-flame = "0.2.0"
tracing-subscriber = "0.3.18"
tracing-texray = "0.2.0"
iai-callgrind = "0.10.2"

common = { path = "../common" }
tracer = { path = "../tracer" }
Expand All @@ -64,6 +65,10 @@ bincode = "1.3.3"
[build-dependencies]
common = { path = "../common" }

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

[lib]
name = "jolt_core"
path = "src/lib.rs"
Expand Down
61 changes: 61 additions & 0 deletions jolt-core/benches/iai.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use ark_bn254::{Fr, G1Projective};
use ark_ec::CurveGroup;
use ark_ff::PrimeField;
use ark_std::{test_rng, UniformRand};
use iai_callgrind::{library_benchmark, library_benchmark_group, main};
use jolt_core::{msm::VariableBaseMSM, poly::dense_mlpoly::DensePolynomial};
use std::hint::black_box;

fn msm_setup<G: CurveGroup>(num_points: usize) -> (Vec<G>, Vec<G::ScalarField>) {
let mut rng = test_rng();

// Generate a vector of random affine points on the curve.
(
vec![G::rand(&mut rng); num_points],
vec![G::ScalarField::rand(&mut rng); num_points],
)
}

fn bound_poly_setup<F: PrimeField>(size: usize) -> (DensePolynomial<F>, F) {
let mut rng = test_rng();

(
DensePolynomial::new(vec![F::rand(&mut rng); size]),
F::rand(&mut rng),
)
}

fn eval_poly_setup<F: PrimeField>(size: usize) -> (DensePolynomial<F>, Vec<F>) {
let mut rng = test_rng();

let poly = DensePolynomial::new(vec![F::rand(&mut rng); size]);
let points = vec![F::rand(&mut rng); poly.get_num_vars()];
(poly, points)
}

#[library_benchmark]
#[bench::long(msm_setup::<G1Projective>(4096))]
fn bench_msm<G: CurveGroup>(input: (Vec<G>, Vec<G::ScalarField>)) -> G {
black_box(VariableBaseMSM::msm(&G::normalize_batch(&input.0), &input.1).unwrap())
}

#[library_benchmark]
#[bench::long(bound_poly_setup::<Fr>(4096))]
fn bench_polynomial_binding<F: PrimeField>(input: (DensePolynomial<F>, F)) {
let (mut poly, val) = input;
black_box(poly.bound_poly_var_top(&val));
}

#[library_benchmark]
#[bench::long(eval_poly_setup::<Fr>(4096))]
fn bench_polynomial_evaluate<F: PrimeField>(input: (DensePolynomial<F>, Vec<F>)) -> F {
let (poly, points) = input;
black_box(poly.evaluate(&points))
}

library_benchmark_group!(
name = jolt_core_ops;
benchmarks = bench_msm, bench_polynomial_binding, bench_polynomial_evaluate
);

main!(library_benchmark_groups = jolt_core_ops);
4 changes: 2 additions & 2 deletions jolt-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub mod benches;
pub mod host;
pub mod jolt;
pub mod lasso;
mod msm;
mod poly;
pub mod msm;
pub mod poly;
pub mod r1cs;
mod subprotocols;
mod utils;
Expand Down

0 comments on commit 6f857f5

Please sign in to comment.