Calculate throughput for pederson hasher
//! Benchmarks for the Parallel Sparse Merkle Tree.
-use criterion::{black_box, BatchSize, Bencher, Criterion};
+use criterion::{black_box, BatchSize, Bencher, Criterion, Throughput};
use models::franklin_crypto::bellman::pairing::bn256::Bn256;
use models::merkle_tree::{hasher::Hasher, PedersenHasher};
+const SMALL_INPUT_SIZE: usize = 16; // 16 bits / 2 bytes
+const BIG_INPUT_SIZE: usize = models::params::MAX_CIRCUIT_PEDERSEN_HASH_BITS; // Biggest supported size.
+
/// Creates a boolean vector for `PedersonHasher` input.
fn generate_input(size: usize) -> Vec<bool> {
(0..size).map(|i| i % 2 == 0).collect()
@@ -11,7 +14,7 @@ fn generate_input(size: usize) -> Vec<bool> {
/// Measures the hashing time for a small input.
fn pedersen_small(b: &mut Bencher<'_>) {
- const INPUT_SIZE: usize = 8; // 1 byte.
+ const INPUT_SIZE: usize = SMALL_INPUT_SIZE;
let hasher = PedersenHasher::<Bn256>::default();
let input: Vec<bool> = generate_input(INPUT_SIZE);
@@ -29,7 +32,7 @@ fn pedersen_small(b: &mut Bencher<'_>) {
/// Measures the hashing time for a (relatively) big input.
fn pedersen_big(b: &mut Bencher<'_>) {
- const INPUT_SIZE: usize = models::params::MAX_CIRCUIT_PEDERSEN_HASH_BITS; // Biggest supported size.
+ const INPUT_SIZE: usize = BIG_INPUT_SIZE;
let hasher = PedersenHasher::<Bn256>::default();
let input: Vec<bool> = generate_input(INPUT_SIZE);
@@ -46,6 +49,13 @@ fn pedersen_big(b: &mut Bencher<'_>) {
}
pub fn bench_pedersen_hasher(c: &mut Criterion) {
- c.bench_function("Pedersen Hasher small input", pedersen_small);
- c.bench_function("Pedersen Hasher big input", pedersen_big);
+ let mut small_input_group = c.benchmark_group("Small input");
+ small_input_group.throughput(Throughput::Bytes((SMALL_INPUT_SIZE / 8) as u64));
+ small_input_group.bench_function("Pedersen Hasher", pedersen_small);
+ small_input_group.finish();
+
+ let mut big_input_group = c.benchmark_group("Big input");
+ big_input_group.throughput(Throughput::Bytes((BIG_INPUT_SIZE / 8) as u64));
+ big_input_group.bench_function("Pedersen Hasher", pedersen_big);
+ big_input_group.finish();
}
