diff --git a/benches/rlp.rs b/benches/rlp.rs index 20ddf25d4..10397db09 100644 --- a/benches/rlp.rs +++ b/benches/rlp.rs @@ -10,7 +10,8 @@ extern crate test; extern crate ethcore_util; use test::Bencher; -use ethcore_util::rlp::{RlpStream}; +use ethcore_util::rlp; +use ethcore_util::rlp::{RlpStream, Rlp, Decodable}; #[bench] fn bench_stream_value(b: &mut Bencher) { @@ -34,6 +35,19 @@ fn bench_stream_nested_empty_lists(b: &mut Bencher) { }); } +#[bench] +fn bench_decode_nested_empty_lists(b: &mut Bencher) { + b.iter( || { + // [ [], [[]], [ [], [[]] ] ] + let data = vec![0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]; + let rlp = Rlp::new(&data); + let v0: Vec = Decodable::decode(&rlp.at(0).unwrap()).unwrap(); + let v1: Vec> = Decodable::decode(&rlp.at(1).unwrap()).unwrap(); + let v2a: Vec = Decodable::decode(&rlp.at(2).unwrap().at(0).unwrap()).unwrap(); + let v2b: Vec> = Decodable::decode(&rlp.at(2).unwrap().at(1).unwrap()).unwrap(); + }); +} + #[bench] fn bench_stream_1000_empty_lists(b: &mut Bencher) { b.iter( || { diff --git a/src/rlp.rs b/src/rlp.rs index 12d94f4a1..e9e175363 100644 --- a/src/rlp.rs +++ b/src/rlp.rs @@ -262,7 +262,7 @@ impl Decodable for Vec where T: Decodable { } } -trait Decoder { +pub trait Decoder { fn read_value(bytes: &[u8]) -> Result where T: FromBytes; }