// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. use std::cmp::Eq; use std::collections::HashSet; use std::fmt::Debug; use std::time::Instant; use criterion::{criterion_group, criterion_main, Criterion}; use smtree::pad_secret::ALL_ZEROS_SECRET; use smtree::{ index::TreeIndex, node_template::{HashNodeSmt, SumNodeSmt}, traits::{Mergeable, Paddable, ProofExtractable, Rand, Serializable, TypeName}, tree::SparseMerkleTree, }; type SMT
= SparseMerkleTree
; type List
= Vec<(TreeIndex, P)>; pub fn bench_build< P: 'static + Mergeable + Paddable + ProofExtractable + Rand + TypeName + Clone + Default + Eq, >( c: &mut Criterion, ) where
::ProofNode: Debug + Clone + Default + Eq + Mergeable + Serializable, { let name = P::get_name(); const LEAF_NUM: u64 = 1_000_000; const TREE_HEIGHT: usize = 256; c.bench_function( &format!( "Build SMT({}) from {} leaves of {}", TREE_HEIGHT, LEAF_NUM, name ), |b| { b.iter(|| { println!("Start!"); let time = Instant::now(); let mut list: List
= Vec::new();
let mut set: HashSet ::ProofNode: Debug + Clone + Default + Eq + Mergeable + Serializable,
{
const LEAF_NUM: u64 = 1_000_000;
const TREE_HEIGHT: usize = 32;
let name = P::get_name();
c.bench_function(
&format!(
"Build SMT({}) from {} leaves of {} by updating each leaf",
TREE_HEIGHT, LEAF_NUM, name
),
|b| {
b.iter(|| {
println!("Start!");
let time = Instant::now();
let mut list: List = Vec::new();
let mut set: HashSet