2016-02-05 13:40:41 +01:00
|
|
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity 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.
|
|
|
|
|
|
|
|
// Parity 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 Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-11-26 01:22:33 +01:00
|
|
|
//! benchmarking for rlp
|
|
|
|
//! should be started with:
|
|
|
|
//! ```bash
|
2015-11-28 10:50:41 +01:00
|
|
|
//! multirust run nightly cargo bench
|
2015-11-26 01:22:33 +01:00
|
|
|
//! ```
|
2016-02-02 02:38:15 +01:00
|
|
|
|
2015-11-26 01:22:33 +01:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate test;
|
|
|
|
extern crate ethcore_util;
|
|
|
|
|
|
|
|
use test::Bencher;
|
2015-11-26 15:43:52 +01:00
|
|
|
use std::str::FromStr;
|
2015-12-09 02:29:34 +01:00
|
|
|
use ethcore_util::rlp::*;
|
2016-08-03 18:05:17 +02:00
|
|
|
use ethcore_util::U256;
|
2015-11-26 01:22:33 +01:00
|
|
|
|
|
|
|
#[bench]
|
2015-11-26 15:43:52 +01:00
|
|
|
fn bench_stream_u64_value(b: &mut Bencher) {
|
2015-11-28 10:50:41 +01:00
|
|
|
b.iter(|| {
|
|
|
|
// u64
|
|
|
|
let mut stream = RlpStream::new();
|
|
|
|
stream.append(&0x1023456789abcdefu64);
|
2015-11-30 17:44:55 +01:00
|
|
|
let _ = stream.out();
|
2015-11-28 10:50:41 +01:00
|
|
|
});
|
2015-11-26 01:22:33 +01:00
|
|
|
}
|
|
|
|
|
2015-11-26 15:43:52 +01:00
|
|
|
#[bench]
|
|
|
|
fn bench_decode_u64_value(b: &mut Bencher) {
|
2015-11-28 10:50:41 +01:00
|
|
|
b.iter(|| {
|
|
|
|
// u64
|
|
|
|
let data = vec![0x88, 0x10, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef];
|
|
|
|
let rlp = Rlp::new(&data);
|
2015-12-09 02:29:34 +01:00
|
|
|
let _: u64 = rlp.as_val();
|
2015-11-28 10:50:41 +01:00
|
|
|
});
|
2015-11-26 15:43:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_stream_u256_value(b: &mut Bencher) {
|
2015-11-28 10:50:41 +01:00
|
|
|
b.iter(|| {
|
|
|
|
// u256
|
|
|
|
let mut stream = RlpStream::new();
|
|
|
|
stream.append(&U256::from_str("8090a0b0c0d0e0f009102030405060770000000000000001000000000\
|
|
|
|
00012f0")
|
|
|
|
.unwrap());
|
2015-11-30 17:44:55 +01:00
|
|
|
let _ = stream.out();
|
2015-11-28 10:50:41 +01:00
|
|
|
});
|
2015-11-26 15:43:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_decode_u256_value(b: &mut Bencher) {
|
2015-11-28 10:50:41 +01:00
|
|
|
b.iter(|| {
|
|
|
|
// u256
|
|
|
|
let data = vec![0xa0, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x09, 0x10, 0x20,
|
|
|
|
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);
|
2015-12-09 02:29:34 +01:00
|
|
|
let _ : U256 = rlp.as_val();
|
2015-11-28 10:50:41 +01:00
|
|
|
});
|
2015-11-26 15:43:52 +01:00
|
|
|
}
|
|
|
|
|
2015-11-26 01:22:33 +01:00
|
|
|
#[bench]
|
|
|
|
fn bench_stream_nested_empty_lists(b: &mut Bencher) {
|
2015-11-28 10:50:41 +01:00
|
|
|
b.iter(|| {
|
|
|
|
// [ [], [[]], [ [], [[]] ] ]
|
|
|
|
let mut stream = RlpStream::new_list(3);
|
2016-02-02 02:31:17 +01:00
|
|
|
stream.begin_list(0);
|
|
|
|
stream.begin_list(1).begin_list(0);
|
|
|
|
stream.begin_list(2).begin_list(0).begin_list(1).begin_list(0);
|
2015-11-30 17:44:55 +01:00
|
|
|
let _ = stream.out();
|
2015-11-28 10:50:41 +01:00
|
|
|
});
|
2015-11-26 01:22:33 +01:00
|
|
|
}
|
|
|
|
|
2015-11-26 02:50:21 +01:00
|
|
|
#[bench]
|
|
|
|
fn bench_decode_nested_empty_lists(b: &mut Bencher) {
|
2015-11-28 10:50:41 +01:00
|
|
|
b.iter(|| {
|
|
|
|
// [ [], [[]], [ [], [[]] ] ]
|
|
|
|
let data = vec![0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0];
|
|
|
|
let rlp = Rlp::new(&data);
|
2015-12-09 02:29:34 +01:00
|
|
|
let _v0: Vec<u16> = rlp.val_at(0);
|
|
|
|
let _v1: Vec<Vec<u16>> = rlp.val_at(1);
|
2015-11-29 09:28:48 +01:00
|
|
|
let nested_rlp = rlp.at(2);
|
2015-12-09 02:29:34 +01:00
|
|
|
let _v2a: Vec<u16> = nested_rlp.val_at(0);
|
|
|
|
let _v2b: Vec<Vec<u16>> = nested_rlp.val_at(1);
|
2015-11-28 10:50:41 +01:00
|
|
|
});
|
2015-11-26 02:50:21 +01:00
|
|
|
}
|
|
|
|
|
2015-11-26 01:22:33 +01:00
|
|
|
#[bench]
|
|
|
|
fn bench_stream_1000_empty_lists(b: &mut Bencher) {
|
2015-11-28 10:50:41 +01:00
|
|
|
b.iter(|| {
|
|
|
|
let mut stream = RlpStream::new_list(1000);
|
|
|
|
for _ in 0..1000 {
|
2016-02-02 02:31:17 +01:00
|
|
|
stream.begin_list(0);
|
2015-11-28 10:50:41 +01:00
|
|
|
}
|
2015-11-30 17:44:55 +01:00
|
|
|
let _ = stream.out();
|
2015-11-28 10:50:41 +01:00
|
|
|
});
|
2015-11-26 01:22:33 +01:00
|
|
|
}
|