EVM bin benches

This commit is contained in:
Tomasz Drwięga 2016-07-11 12:15:22 +02:00
parent bdf4446173
commit edaf24a2ce
3 changed files with 94 additions and 4 deletions

View File

@ -4,6 +4,14 @@ description = "Parity's EVM implementation"
version = "0.1.0"
authors = ["Ethcore <admin@ethcore.io>"]
[lib]
name = "evm"
path = "./src/main.rs"
[[bin]]
name = "evm"
path = "./src/main.rs"
[dependencies]
rustc-serialize = "0.3"
docopt = { version = "0.6" }

61
evmbin/benches/mod.rs Normal file
View File

@ -0,0 +1,61 @@
// 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/>.
//! benchmarking for EVM
//! should be started with:
//! ```bash
//! multirust run nightly cargo bench
//! ```
#![feature(test)]
extern crate test;
extern crate ethcore;
extern crate evm;
extern crate ethcore_util;
extern crate rustc_serialize;
use self::test::{Bencher, black_box};
use evm::run_vm;
use ethcore::action_params::ActionParams;
use ethcore_util::{U256, Uint};
use rustc_serialize::hex::FromHex;
#[bench]
fn simple_loop_usize(b: &mut Bencher) {
simple_loop(U256::from(::std::usize::MAX), b)
}
#[bench]
fn simple_loop_u256(b: &mut Bencher) {
simple_loop(!U256::zero(), b)
}
fn simple_loop(gas: U256, b: &mut Bencher) {
let code = black_box(
"606060405260005b620f42408112156019575b6001016007565b600081905550600680602b6000396000f3606060405200".from_hex().unwrap()
);
b.iter(|| {
let mut params = ActionParams::default();
params.gas = gas;
params.code = Some(code.clone());
run_vm(params)
});
}

View File

@ -25,7 +25,7 @@ extern crate ethcore_util as util;
mod ext;
use std::time::Instant;
use std::time::{Instant, Duration};
use std::str::FromStr;
use docopt::Docopt;
use util::{U256, FromHex, Uint, Bytes};
@ -58,6 +58,15 @@ fn main() {
params.code = Some(args.code());
params.data = args.data();
let result = run_vm(params);
println!("Gas used: {:?}", result.gas_used);
println!("Output: {:?}", result.output);
println!("Time: {}.{:.9}s", result.time.as_secs(), result.time.subsec_nanos());
}
/// Execute VM with given `ActionParams`
pub fn run_vm(params: ActionParams) -> ExecutionResults {
let initial_gas = params.gas;
let factory = Factory::new(VMType::Interpreter);
let mut vm = factory.create(params.gas);
let mut ext = ext::FakeExt::default();
@ -66,9 +75,21 @@ fn main() {
let gas_left = vm.exec(params, &mut ext).finalize(ext).expect("OK");
let duration = start.elapsed();
println!("Gas used: {:?}", args.gas() - gas_left);
println!("Output: {:?}", "");
println!("Time: {}.{:.9}s", duration.as_secs(), duration.subsec_nanos());
ExecutionResults {
gas_used: initial_gas - gas_left,
output: Vec::new(),
time: duration,
}
}
/// VM execution results
pub struct ExecutionResults {
/// Used gas
pub gas_used: U256,
/// Output as bytes
pub output: Vec<u8>,
/// Time Taken
pub time: Duration,
}
#[derive(Debug, RustcDecodable)]