Skip to content

Commit

Permalink
Add privacy-scaling-explorations/halo2#40 to criterion bench
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Oct 20, 2023
1 parent 512bb03 commit 25d80d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
15 changes: 15 additions & 0 deletions benches/msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use ff::Field;
use group::prime::PrimeCurveAffine;
use halo2curves::bn256::{Fr as Scalar, G1Affine as Point};
use halo2curves::msm::{best_multiexp, multiexp_serial};
use halo2curves::msm_halo2_pr40::{MultiExp, MultiExpContext};
use maybe_rayon::current_thread_index;
use maybe_rayon::prelude::{IntoParallelIterator, ParallelIterator};
use rand_core::SeedableRng;
Expand Down Expand Up @@ -108,6 +109,20 @@ fn msm(c: &mut Criterion) {
})
})
.sample_size(SAMPLE_SIZE);
group
.bench_function(BenchmarkId::new("multicore-pr40", k), |b| {
assert!(k < 64);
let n: usize = 1 << k;
b.iter(
|| {
let msm = MultiExp::new(&bases[..n]);
let mut ctx = MultiExpContext::default();
// evaluate(_, _, true): assume some might be infinity or P = -Q or P = Q
msm.evaluate(&mut ctx, &coeffs[..n], true)
}
);
})
.sample_size(10);
}
group.finish();
}
Expand Down
20 changes: 14 additions & 6 deletions src/msm_halo2_pr40.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,14 +859,22 @@ fn accumulate_buckets<C: CurveAffineExt>(

#[cfg(test)]
use rand_xorshift::XorShiftRng;
#[cfg(test)]
use crate::msm::best_multiexp;
#[cfg(test)]
use crate::bn256::{Fr as Scalar, G1Affine as Point};
#[cfg(test)]
use ff::Field;
#[cfg(test)]
use maybe_rayon::current_thread_index;
#[cfg(test)]
use maybe_rayon::prelude::{IntoParallelIterator, ParallelIterator};
#[cfg(test)]
use rand_core::SeedableRng;
#[cfg(test)]
use std::time::SystemTime;

#[cfg(test)]
const SEED: [u8; 16] = [
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5,
];
Expand Down Expand Up @@ -1009,8 +1017,8 @@ fn test_multiexp_best_c() {
let res_base = best_multiexp(coeffs, bases);
let res_base_affine: Point = res_base.into();

let mut best_c = 0;
let mut best_duration = usize::MAX;
let mut _best_c = 0;
let mut _best_duration = usize::MAX;
for c in 4..=21 {
// Allocate memory so it doesn't impact performance
ctx.allocate(n, c);
Expand All @@ -1021,14 +1029,14 @@ fn test_multiexp_best_c() {
end_timer!(start);
// let duration = stop_measure(start);

// if duration < best_duration {
// best_duration = duration;
// best_c = c;
// if duration < _best_duration {
// _best_duration = duration;
// _best_c = c;
// }

let res_affine: Point = res.into();
assert_eq!(res_base_affine, res_affine);
}
// println!("{}: {}", n, best_c);
// println!("{}: {}", n, _best_c);
}
}

0 comments on commit 25d80d7

Please sign in to comment.