Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Update to criterion 0.5 #1

Open
wants to merge 1 commit into
base: borsh
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bincode = { version = "1.3.3" }

[dev-dependencies]
hex = "0.3"
criterion = "0.3"
criterion = "0.5"
bincode = "1"
rand_chacha = "0.2"

Expand Down
19 changes: 10 additions & 9 deletions benches/generators.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
use bulletproofs::{BulletproofGens, PedersenGens};

#[macro_use]
extern crate criterion;
use criterion::Criterion;
use criterion::BenchmarkId;
use criterion::{Criterion, criterion_main, criterion_group};

fn pc_gens(c: &mut Criterion) {
c.bench_function("PedersenGens::new", |b| b.iter(|| PedersenGens::default()));
}

fn bp_gens(c: &mut Criterion) {
c.bench_function_over_inputs(
"BulletproofGens::new",
|b, size| b.iter(|| BulletproofGens::new(*size, 1)),
(0..10).map(|i| 2 << i),
);
let mut group = c.benchmark_group("BulletproofGens::new");
for size in (0..10).map(|i| 2 << i) {
group.bench_with_input(
BenchmarkId::from_parameter(size),
&size,
|b, &size| b.iter(|| BulletproofGens::new(size, 1)),
);
}
}

criterion_group! {
Expand Down
32 changes: 16 additions & 16 deletions benches/linear_proof.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
#![allow(non_snake_case)]

#[macro_use]
extern crate criterion;
use criterion::Criterion;

extern crate bulletproofs;
extern crate curve25519_dalek;
extern crate merlin;
extern crate rand;
use criterion::BenchmarkId;
use criterion::{Criterion, criterion_group, criterion_main};

use core::iter;

Expand All @@ -22,8 +16,11 @@ use merlin::Transcript;
static TEST_SIZES: [usize; 5] = [64, 128, 256, 512, 1024];

fn create_linear_proof_helper(c: &mut Criterion) {
c.bench_function_over_inputs(
"linear proof creation",
let mut group = c.benchmark_group("linear proof creation");
for size in TEST_SIZES {
group.bench_with_input(
BenchmarkId::from_parameter(size),
&size,
move |bench, n| {
let mut rng = rand::thread_rng();

Expand Down Expand Up @@ -68,8 +65,8 @@ fn create_linear_proof_helper(c: &mut Criterion) {
.unwrap();
})
},
TEST_SIZES,
);
);
}
}

/// Copied from src/inner_product_proof.rs
Expand Down Expand Up @@ -99,8 +96,11 @@ criterion_group! {
}

fn linear_verify(c: &mut Criterion) {
c.bench_function_over_inputs(
"linear proof verification",
let mut group = c.benchmark_group("linear proof verification");
for size in TEST_SIZES {
group.bench_with_input(
BenchmarkId::from_parameter(size),
&size,
move |bench, n| {
let bp_gens = BulletproofGens::new(*n, 1);
let mut rng = rand::thread_rng();
Expand Down Expand Up @@ -156,8 +156,8 @@ fn linear_verify(c: &mut Criterion) {
.unwrap();
});
},
TEST_SIZES,
);
);
}
}

criterion_group! {
Expand Down
4 changes: 1 addition & 3 deletions benches/r1cs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![allow(non_snake_case)]

#[macro_use]
extern crate criterion;
use criterion::Criterion;
use criterion::{Criterion, criterion_group, criterion_main};

// Code below copied from ../tests/r1cs.rs
//
Expand Down
31 changes: 18 additions & 13 deletions benches/range_proof.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(non_snake_case)]
#[macro_use]
extern crate criterion;
use criterion::Criterion;
use criterion::BenchmarkId;
use criterion::{Criterion, criterion_group, criterion_main};

use rand;
use rand::Rng;
Expand All @@ -17,10 +16,13 @@ static AGGREGATION_SIZES: [usize; 6] = [1, 2, 4, 8, 16, 32];

fn create_aggregated_rangeproof_helper(n: usize, c: &mut Criterion) {
let label = format!("Aggregated {}-bit rangeproof creation", n);
let mut group = c.benchmark_group(&label);

c.bench_function_over_inputs(
&label,
move |b, &&m| {
for size in AGGREGATION_SIZES {
group.bench_with_input(
BenchmarkId::from_parameter(size),
&size,
move |b, &m| {
let pc_gens = PedersenGens::default();
let bp_gens = BulletproofGens::new(n, m);
let mut rng = rand::thread_rng();
Expand All @@ -43,8 +45,8 @@ fn create_aggregated_rangeproof_helper(n: usize, c: &mut Criterion) {
)
})
},
&AGGREGATION_SIZES,
);
);
}
}

fn create_aggregated_rangeproof_n_8(c: &mut Criterion) {
Expand All @@ -65,10 +67,13 @@ fn create_aggregated_rangeproof_n_64(c: &mut Criterion) {

fn verify_aggregated_rangeproof_helper(n: usize, c: &mut Criterion) {
let label = format!("Aggregated {}-bit rangeproof verification", n);
let mut group = c.benchmark_group(&label);

c.bench_function_over_inputs(
&label,
move |b, &&m| {
for size in AGGREGATION_SIZES {
group.bench_with_input(
BenchmarkId::from_parameter(size),
&size,
move |b, &m| {
let pc_gens = PedersenGens::default();
let bp_gens = BulletproofGens::new(n, m);
let mut rng = rand::thread_rng();
Expand All @@ -95,8 +100,8 @@ fn verify_aggregated_rangeproof_helper(n: usize, c: &mut Criterion) {
proof.verify_multiple(&bp_gens, &pc_gens, &mut transcript, &value_commitments, n)
});
},
&AGGREGATION_SIZES,
);
);
}
}

fn verify_aggregated_rangeproof_n_8(c: &mut Criterion) {
Expand Down