From 79cba2e500b29f77cacfe0fcc68402d221f2330d Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 10 Sep 2019 12:51:23 +0300 Subject: [PATCH] run against long examples --- examples/long.rs | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 examples/long.rs diff --git a/examples/long.rs b/examples/long.rs new file mode 100644 index 000000000..bb2f2d481 --- /dev/null +++ b/examples/long.rs @@ -0,0 +1,73 @@ +use zcash_mmr::{Entry, EntryLink, NodeData, Tree}; + +#[path= "lib/shared.rs"] +mod share; + +fn prepare_tree(vec: &Vec) -> Tree { + + assert!(vec.len() > 0); + + // integer log2 of (vec.len()+1), -1 + let mut h = (32 - ((vec.len()+1) as u32).leading_zeros() - 1)-1; + let mut peak_pos = (1 << (h+1)) - 1; + let mut nodes = Vec::new(); + + loop { + + if peak_pos > vec.len() { + // left child, -2^h + peak_pos = peak_pos - (1< { eprintln!("writer []"); std::process::exit(1); }, + Some(number) => { + number.parse::().expect("invalid number") + } + }; + + let long_vec = share::NodeDataIterator::new().take(number) + .collect::>(); + + let now = std::time::Instant::now(); + + let tree = prepare_tree(&long_vec); + + println!("Tree final root: {}-{}", + tree.root_node().expect("root").data().start_height, + tree.root_node().expect("root").data().end_height, + ); + + println!("Prepare tree of {} length: {} ns / {} mcs / {} ms", + number, + now.elapsed().as_nanos(), now.elapsed().as_micros(), now.elapsed().as_millis() + ); +}