fixed rlp benchmarks, added triehash benchmarks
This commit is contained in:
parent
0e343d078c
commit
f10e72caeb
@ -11,7 +11,7 @@ extern crate ethcore_util;
|
|||||||
|
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use ethcore_util::rlp::{RlpStream, Rlp, Decodable};
|
use ethcore_util::rlp::*;
|
||||||
use ethcore_util::uint::U256;
|
use ethcore_util::uint::U256;
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
@ -30,7 +30,7 @@ fn bench_decode_u64_value(b: &mut Bencher) {
|
|||||||
// u64
|
// u64
|
||||||
let data = vec![0x88, 0x10, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef];
|
let data = vec![0x88, 0x10, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef];
|
||||||
let rlp = Rlp::new(&data);
|
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,
|
0x30, 0x40, 0x50, 0x60, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xf0];
|
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xf0];
|
||||||
let rlp = Rlp::new(&data);
|
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 data = vec![0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0];
|
||||||
let rlp = Rlp::new(&data);
|
let rlp = Rlp::new(&data);
|
||||||
let _v0: Vec<u16> = Decodable::decode(&rlp.at(0));
|
let _v0: Vec<u16> = rlp.val_at(0);
|
||||||
let _v1: Vec<Vec<u16>> = Decodable::decode(&rlp.at(1));
|
let _v1: Vec<Vec<u16>> = rlp.val_at(1);
|
||||||
let nested_rlp = rlp.at(2);
|
let nested_rlp = rlp.at(2);
|
||||||
let _v2a: Vec<u16> = Decodable::decode(&nested_rlp.at(0));
|
let _v2a: Vec<u16> = nested_rlp.val_at(0);
|
||||||
let _v2b: Vec<Vec<u16>> = Decodable::decode(&nested_rlp.at(1));
|
let _v2b: Vec<Vec<u16>> = nested_rlp.val_at(1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ use test::Bencher;
|
|||||||
use ethcore_util::hash::*;
|
use ethcore_util::hash::*;
|
||||||
use ethcore_util::bytes::*;
|
use ethcore_util::bytes::*;
|
||||||
use ethcore_util::trie::*;
|
use ethcore_util::trie::*;
|
||||||
|
use ethcore_util::triehash::*;
|
||||||
use ethcore_util::sha3::*;
|
use ethcore_util::sha3::*;
|
||||||
|
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ fn random_value(seed: &mut H256) -> Bytes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[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 d: Vec<(Bytes, Bytes)> = Vec::new();
|
||||||
let mut seed = H256::new();
|
let mut seed = H256::new();
|
||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
@ -58,7 +59,22 @@ fn insertions_six_high(b: &mut Bencher) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[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 alphabet = b"@QWERTYUIOPASDFGHJKLZXCVBNM[/]^_";
|
||||||
let mut d: Vec<(Bytes, Bytes)> = Vec::new();
|
let mut d: Vec<(Bytes, Bytes)> = Vec::new();
|
||||||
let mut seed = H256::new();
|
let mut seed = H256::new();
|
||||||
@ -77,7 +93,22 @@ fn insertions_six_mid(b: &mut Bencher) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[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 alphabet = b"@QWERTYUIOPASDFGHJKLZXCVBNM[/]^_";
|
||||||
let mut d: Vec<(Bytes, Bytes)> = Vec::new();
|
let mut d: Vec<(Bytes, Bytes)> = Vec::new();
|
||||||
let mut seed = H256::new();
|
let mut seed = H256::new();
|
||||||
@ -96,7 +127,23 @@ fn insertions_random_mid(b: &mut Bencher) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[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 alphabet = b"abcdef";
|
||||||
let mut d: Vec<(Bytes, Bytes)> = Vec::new();
|
let mut d: Vec<(Bytes, Bytes)> = Vec::new();
|
||||||
let mut seed = H256::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]
|
#[bench]
|
||||||
fn sha3x1000(b: &mut Bencher) {
|
fn sha3x1000(b: &mut Bencher) {
|
||||||
b.iter(||{
|
b.iter(||{
|
||||||
|
Loading…
Reference in New Issue
Block a user