From f10e72caeb3f8fac76610f1e697184a06a891341 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 9 Dec 2015 02:29:34 +0100 Subject: [PATCH] fixed rlp benchmarks, added triehash benchmarks --- benches/rlp.rs | 14 +++++----- benches/trie.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/benches/rlp.rs b/benches/rlp.rs index 1160e311f..8bc7599e4 100644 --- a/benches/rlp.rs +++ b/benches/rlp.rs @@ -11,7 +11,7 @@ extern crate ethcore_util; use test::Bencher; use std::str::FromStr; -use ethcore_util::rlp::{RlpStream, Rlp, Decodable}; +use ethcore_util::rlp::*; use ethcore_util::uint::U256; #[bench] @@ -30,7 +30,7 @@ fn bench_decode_u64_value(b: &mut Bencher) { // u64 let data = vec![0x88, 0x10, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]; let rlp = Rlp::new(&data); - let _ = u64::decode(&rlp); + let _: u64 = rlp.as_val(); }); } @@ -54,7 +54,7 @@ fn bench_decode_u256_value(b: &mut Bencher) { 0x30, 0x40, 0x50, 0x60, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xf0]; let rlp = Rlp::new(&data); - let _ = U256::decode(&rlp); + let _ : U256 = rlp.as_val(); }); } @@ -76,11 +76,11 @@ fn bench_decode_nested_empty_lists(b: &mut Bencher) { // [ [], [[]], [ [], [[]] ] ] let data = vec![0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]; let rlp = Rlp::new(&data); - let _v0: Vec = Decodable::decode(&rlp.at(0)); - let _v1: Vec> = Decodable::decode(&rlp.at(1)); + let _v0: Vec = rlp.val_at(0); + let _v1: Vec> = rlp.val_at(1); let nested_rlp = rlp.at(2); - let _v2a: Vec = Decodable::decode(&nested_rlp.at(0)); - let _v2b: Vec> = Decodable::decode(&nested_rlp.at(1)); + let _v2a: Vec = nested_rlp.val_at(0); + let _v2b: Vec> = nested_rlp.val_at(1); }); } diff --git a/benches/trie.rs b/benches/trie.rs index 2865c5778..a8cd407cf 100644 --- a/benches/trie.rs +++ b/benches/trie.rs @@ -10,6 +10,7 @@ use test::Bencher; use ethcore_util::hash::*; use ethcore_util::bytes::*; use ethcore_util::trie::*; +use ethcore_util::triehash::*; use ethcore_util::sha3::*; @@ -40,7 +41,7 @@ fn random_value(seed: &mut H256) -> Bytes { } #[bench] -fn insertions_six_high(b: &mut Bencher) { +fn trie_insertions_six_high(b: &mut Bencher) { let mut d: Vec<(Bytes, Bytes)> = Vec::new(); let mut seed = H256::new(); for _ in 0..1000 { @@ -58,7 +59,22 @@ fn insertions_six_high(b: &mut Bencher) { } #[bench] -fn insertions_six_mid(b: &mut Bencher) { +fn triehash_insertions_six_high(b: &mut Bencher) { + let mut d: Vec<(Bytes, Bytes)> = Vec::new(); + let mut seed = H256::new(); + for _ in 0..1000 { + let k = random_bytes(6, 0, &mut seed); + let v = random_value(&mut seed); + d.push((k, v)) + } + + b.iter(&||{ + trie_root(d.clone()); + }) +} + +#[bench] +fn trie_insertions_six_mid(b: &mut Bencher) { let alphabet = b"@QWERTYUIOPASDFGHJKLZXCVBNM[/]^_"; let mut d: Vec<(Bytes, Bytes)> = Vec::new(); let mut seed = H256::new(); @@ -77,7 +93,22 @@ fn insertions_six_mid(b: &mut Bencher) { } #[bench] -fn insertions_random_mid(b: &mut Bencher) { +fn triehash_insertions_six_mid(b: &mut Bencher) { + let alphabet = b"@QWERTYUIOPASDFGHJKLZXCVBNM[/]^_"; + let mut d: Vec<(Bytes, Bytes)> = Vec::new(); + let mut seed = H256::new(); + for _ in 0..1000 { + let k = random_word(alphabet, 6, 0, &mut seed); + let v = random_value(&mut seed); + d.push((k, v)) + } + b.iter(||{ + trie_root(d.clone()); + }) +} + +#[bench] +fn trie_insertions_random_mid(b: &mut Bencher) { let alphabet = b"@QWERTYUIOPASDFGHJKLZXCVBNM[/]^_"; let mut d: Vec<(Bytes, Bytes)> = Vec::new(); let mut seed = H256::new(); @@ -96,7 +127,23 @@ fn insertions_random_mid(b: &mut Bencher) { } #[bench] -fn insertions_six_low(b: &mut Bencher) { +fn triehash_insertions_random_mid(b: &mut Bencher) { + let alphabet = b"@QWERTYUIOPASDFGHJKLZXCVBNM[/]^_"; + let mut d: Vec<(Bytes, Bytes)> = Vec::new(); + let mut seed = H256::new(); + for _ in 0..1000 { + let k = random_word(alphabet, 1, 5, &mut seed); + let v = random_value(&mut seed); + d.push((k, v)) + } + + b.iter(||{ + trie_root(d.clone()); + }) +} + +#[bench] +fn trie_insertions_six_low(b: &mut Bencher) { let alphabet = b"abcdef"; let mut d: Vec<(Bytes, Bytes)> = Vec::new(); let mut seed = H256::new(); @@ -114,6 +161,22 @@ fn insertions_six_low(b: &mut Bencher) { }) } +#[bench] +fn triehash_insertions_six_low(b: &mut Bencher) { + let alphabet = b"abcdef"; + let mut d: Vec<(Bytes, Bytes)> = Vec::new(); + let mut seed = H256::new(); + for _ in 0..1000 { + let k = random_word(alphabet, 6, 0, &mut seed); + let v = random_value(&mut seed); + d.push((k, v)) + } + + b.iter(||{ + trie_root(d.clone()); + }) +} + #[bench] fn sha3x1000(b: &mut Bencher) { b.iter(||{