// Copyright 2015-2020 Parity Technologies (UK) Ltd. // This file is part of Tetsy Vapory. // Tetsy Vapory is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // Tetsy Vapory is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Tetsy Vapory. If not, see . //! Benchmarking RlpNodeCodec decoding performance extern crate criterion; extern crate patricia_trie_vapory as vaptrie; extern crate tetsy_trie_db; extern crate vapory_types; extern crate tetsy_rlp; use criterion::{Criterion, criterion_group, criterion_main}; use vapory_types::H256; use vaptrie::RlpNodeCodec; use tetsy_rlp::RlpStream; use tetsy_trie_db::NodeCodec; fn decoding(c: &mut Criterion) { c.bench_function("decode leaf (inline)", |b| { let mut stream = RlpStream::new_list(2); stream.append(&"cat").append(&"dog"); let data = stream.out(); b.iter(|| { RlpNodeCodec::decode(&data) }); }); c.bench_function("decode extension (inline)", |b| { let mut stream = RlpStream::new_list(2); let payload = vec![0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9u8]; stream.append(&"").append(&payload); let data = stream.out(); b.iter(|| { RlpNodeCodec::decode(&data) }); }); c.bench_function("decode extension (hash)", |b| { let mut stream = RlpStream::new_list(2); let payload = H256::random(); stream.append(&"").append(&payload); let data = stream.out(); b.iter(|| { RlpNodeCodec::decode(&data) }); }); c.bench_function("decode branch (hash)", |b| { let mut stream = RlpStream::new_list(17); for _ in 0..17 { stream.append(&H256::random()); } let data = stream.out(); b.iter(|| { RlpNodeCodec::decode(&data) }); }); c.bench_function("decode branch (inline)", |b| { let mut stream = RlpStream::new_list(17); for _ in 0..17 { stream.append(&[&H256::random().as_bytes(), H256::random().as_bytes()].concat()); } let data = stream.out(); b.iter(|| { RlpNodeCodec::decode(&data) }); }); c.bench_function("decode empty data", |b| { let mut stream = RlpStream::new(); stream.append_empty_data(); let data = stream.out(); b.iter(|| { RlpNodeCodec::decode(&data)}); }); } criterion_group!(benches, decoding); criterion_main!(benches);