Skip to content

Commit

Permalink
bechmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanting Zhang committed Feb 9, 2024
1 parent 047f8e6 commit 325c29d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
15 changes: 12 additions & 3 deletions benches/grumpkin_msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,32 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("GPU");
group.sample_size(20);

let indices = (0..(npoints as u32)).rev().collect::<Vec<_>>();

group.bench_function(format!("2**{} points", bench_npow), |b| {
b.iter(|| {
let _ = grumpkin_msm::bn256::msm_aux(&points, &scalars, None);
})
});

scalars.reverse();
group.bench_function(format!("2**{} points rev", bench_npow), |b| {
b.iter(|| {
let _ = grumpkin_msm::bn256::msm_aux(&points, &scalars, Some(indices.as_slice()));
})
});

let context = grumpkin_msm::bn256::init(&points);

let indices = (0..(npoints as u32)).rev().collect::<Vec<_>>();
scalars.reverse();
group.bench_function(
format!("preallocate 2**{} points", bench_npow),
|b| {
b.iter(|| {
let _ = grumpkin_msm::bn256::with_context_aux(
&context,
&scalars,
Some(indices.as_slice()),
None,
);
})
},
Expand All @@ -93,7 +102,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|b| {
b.iter(|| {
let _ = grumpkin_msm::bn256::with_context_aux(
&context, &scalars, None,
&context, &scalars, Some(indices.as_slice()),
);
})
},
Expand Down
2 changes: 1 addition & 1 deletion examples/grumpkin_msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use grumpkin_msm::cuda_available;

fn main() {
let bench_npow: usize = std::env::var("BENCH_NPOW")
.unwrap_or("22".to_string())
.unwrap_or("23".to_string())
.parse()
.unwrap();
let npoints: usize = 1 << bench_npow;
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ macro_rules! impl_msm {

/// An indexed MSM. We do not check if the indices are valid, i.e.
/// for i in 0..nscalars, 0 <= indices[i] < npoints
///
/// Also, this version carries a performance penalty that all the
/// points must be moved onto the GPU once instead of in batches.
/// If the points are to be reused, please use the [`MSMContext`] API
pub fn indexed_msm(
points: &[$affine],
scalars: &[$scalar],
Expand Down
4 changes: 4 additions & 0 deletions src/pasta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ macro_rules! impl_pasta {

/// An indexed MSM. We do not check if the indices are valid, i.e.
/// for i in 0..nscalars, 0 <= indices[i] < npoints
///
/// Also, this version carries a performance penalty that all the
/// points must be moved onto the GPU once instead of in batches.
/// If the points are to be reused, please use the [`MSMContext`] API
pub fn indexed_msm(
points: &[$affine],
scalars: &[$scalar],
Expand Down

0 comments on commit 325c29d

Please sign in to comment.