2020-09-22 14:53:52 +02:00
|
|
|
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of OpenEthereum.
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
// OpenEthereum is free software: you can redistribute it and/or modify
|
2018-11-06 14:22:44 +01:00
|
|
|
// 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.
|
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
// OpenEthereum is distributed in the hope that it will be useful,
|
2018-11-06 14:22:44 +01:00
|
|
|
// 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
|
2020-09-22 14:53:52 +02:00
|
|
|
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
2018-11-06 14:22:44 +01:00
|
|
|
|
|
|
|
//! benchmarking for EVM
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate criterion;
|
|
|
|
extern crate bit_set;
|
|
|
|
extern crate ethereum_types;
|
|
|
|
extern crate evm;
|
2020-08-05 06:08:03 +02:00
|
|
|
extern crate heapsize;
|
2018-11-06 14:22:44 +01:00
|
|
|
extern crate keccak_hash as hash;
|
|
|
|
extern crate memory_cache;
|
|
|
|
extern crate parity_bytes as bytes;
|
2020-08-05 06:08:03 +02:00
|
|
|
extern crate parking_lot;
|
2018-11-06 14:22:44 +01:00
|
|
|
extern crate rustc_hex;
|
2020-08-05 06:08:03 +02:00
|
|
|
extern crate vm;
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
use criterion::{black_box, Bencher, Criterion};
|
|
|
|
use ethereum_types::{Address, U256};
|
2018-11-06 14:22:44 +01:00
|
|
|
use evm::Factory;
|
|
|
|
use rustc_hex::FromHex;
|
2020-08-05 06:08:03 +02:00
|
|
|
use std::{str::FromStr, sync::Arc};
|
|
|
|
use vm::{tests::FakeExt, ActionParams, Ext, GasLeft, Result};
|
2018-11-06 14:22:44 +01:00
|
|
|
|
|
|
|
criterion_group!(
|
2020-08-05 06:08:03 +02:00
|
|
|
basic,
|
|
|
|
simple_loop_log0_usize,
|
|
|
|
simple_loop_log0_u256,
|
|
|
|
mem_gas_calculation_same_usize,
|
|
|
|
mem_gas_calculation_same_u256,
|
|
|
|
mem_gas_calculation_increasing_usize,
|
|
|
|
mem_gas_calculation_increasing_u256,
|
|
|
|
blockhash_mulmod_small,
|
|
|
|
blockhash_mulmod_large,
|
2018-11-06 14:22:44 +01:00
|
|
|
);
|
|
|
|
criterion_main!(basic);
|
|
|
|
|
|
|
|
fn simple_loop_log0_usize(b: &mut Criterion) {
|
2020-08-05 06:08:03 +02:00
|
|
|
b.bench_function("simple_loop_log0_usize", |b| {
|
|
|
|
simple_loop_log0(U256::from(::std::usize::MAX), b);
|
|
|
|
});
|
2018-11-06 14:22:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn simple_loop_log0_u256(b: &mut Criterion) {
|
2020-08-05 06:08:03 +02:00
|
|
|
b.bench_function("simple_loop_log0_u256", |b| {
|
|
|
|
simple_loop_log0(!U256::zero(), b);
|
|
|
|
});
|
2018-11-06 14:22:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn simple_loop_log0(gas: U256, b: &mut Bencher) {
|
2020-08-05 06:08:03 +02:00
|
|
|
let factory = Factory::default();
|
|
|
|
let mut ext = FakeExt::new();
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
|
|
|
let code = black_box("62ffffff5b600190036000600fa0600357".from_hex().unwrap());
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
b.iter(|| {
|
|
|
|
let mut params = ActionParams::default();
|
|
|
|
params.address = address.clone();
|
|
|
|
params.gas = gas;
|
|
|
|
params.code = Some(Arc::new(code.clone()));
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
let vm = factory.create(params, ext.schedule(), 0);
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
result(vm.exec(&mut ext).ok().unwrap())
|
|
|
|
});
|
2018-11-06 14:22:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mem_gas_calculation_same_usize(b: &mut Criterion) {
|
2020-08-05 06:08:03 +02:00
|
|
|
b.bench_function("mem_gas_calculation_same_usize", |b| {
|
|
|
|
mem_gas_calculation_same(U256::from(::std::usize::MAX), b);
|
|
|
|
});
|
2018-11-06 14:22:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mem_gas_calculation_same_u256(b: &mut Criterion) {
|
2020-08-05 06:08:03 +02:00
|
|
|
b.bench_function("mem_gas_calculation_same_u256", |b| {
|
|
|
|
mem_gas_calculation_same(!U256::zero(), b);
|
|
|
|
});
|
2018-11-06 14:22:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mem_gas_calculation_same(gas: U256, b: &mut Bencher) {
|
2020-08-05 06:08:03 +02:00
|
|
|
let factory = Factory::default();
|
|
|
|
let mut ext = FakeExt::new();
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
b.iter(|| {
|
|
|
|
let code = black_box(
|
|
|
|
"6110006001556001546000555b610fff805560016000540380600055600c57"
|
|
|
|
.from_hex()
|
|
|
|
.unwrap(),
|
|
|
|
);
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
let mut params = ActionParams::default();
|
|
|
|
params.address = address.clone();
|
|
|
|
params.gas = gas;
|
|
|
|
params.code = Some(Arc::new(code.clone()));
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
let vm = factory.create(params, ext.schedule(), 0);
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
result(vm.exec(&mut ext).ok().unwrap())
|
|
|
|
});
|
2018-11-06 14:22:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mem_gas_calculation_increasing_usize(b: &mut Criterion) {
|
2020-08-05 06:08:03 +02:00
|
|
|
b.bench_function("mem_gas_calculation_increasing_usize", |b| {
|
|
|
|
mem_gas_calculation_increasing(U256::from(::std::usize::MAX), b);
|
|
|
|
});
|
2018-11-06 14:22:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mem_gas_calculation_increasing_u256(b: &mut Criterion) {
|
2020-08-05 06:08:03 +02:00
|
|
|
b.bench_function("mem_gas_calculation_increasing_u256", |b| {
|
|
|
|
mem_gas_calculation_increasing(!U256::zero(), b);
|
|
|
|
});
|
2018-11-06 14:22:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mem_gas_calculation_increasing(gas: U256, b: &mut Bencher) {
|
2020-08-05 06:08:03 +02:00
|
|
|
let factory = Factory::default();
|
|
|
|
let mut ext = FakeExt::new();
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
b.iter(|| {
|
|
|
|
let code = black_box(
|
|
|
|
"6110006001556001546000555b610fff60005401805560016000540380600055600c57"
|
|
|
|
.from_hex()
|
|
|
|
.unwrap(),
|
|
|
|
);
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
let mut params = ActionParams::default();
|
|
|
|
params.address = address.clone();
|
|
|
|
params.gas = gas;
|
|
|
|
params.code = Some(Arc::new(code.clone()));
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
let vm = factory.create(params, ext.schedule(), 0);
|
2018-11-06 14:22:44 +01:00
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
result(vm.exec(&mut ext).ok().unwrap())
|
|
|
|
});
|
2018-11-06 14:22:44 +01:00
|
|
|
}
|
|
|
|
|
2019-05-10 13:48:52 +02:00
|
|
|
fn blockhash_mulmod_small(b: &mut Criterion) {
|
2020-08-05 06:08:03 +02:00
|
|
|
b.bench_function("blockhash_mulmod_small", |b| {
|
2019-05-10 13:48:52 +02:00
|
|
|
let factory = Factory::default();
|
|
|
|
let mut ext = FakeExt::new();
|
|
|
|
|
|
|
|
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
let code = black_box(
|
|
|
|
"6080604052348015600f57600080fd5b5060005a90505b60c881111560de5760017effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80095060017effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80095060017effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80095060017effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80095060017effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8009505a90506016565b506035806100ed6000396000f3fe6080604052600080fdfea165627a7a72305820bde4a0ac6d0fac28fc879244baf8a6a0eda514bc95fb7ecbcaaebf2556e2687c0029".from_hex().unwrap()
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut params = ActionParams::default();
|
|
|
|
params.address = address.clone();
|
|
|
|
params.gas = U256::from(4_000u64);
|
|
|
|
params.code = Some(Arc::new(code.clone()));
|
|
|
|
|
|
|
|
let vm = factory.create(params, ext.schedule(), 0);
|
|
|
|
|
|
|
|
result(vm.exec(&mut ext).ok().unwrap())
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn blockhash_mulmod_large(b: &mut Criterion) {
|
2020-08-05 06:08:03 +02:00
|
|
|
b.bench_function("blockhash_mulmod_large", |b| {
|
2019-05-10 13:48:52 +02:00
|
|
|
let factory = Factory::default();
|
|
|
|
let mut ext = FakeExt::new();
|
|
|
|
|
|
|
|
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
let code = black_box(
|
|
|
|
"608060405234801561001057600080fd5b5060005a90505b60c8811115610177577efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff17efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff08009507efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff17efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff08009507efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff17efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff08009507efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff17efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff08009507efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff17efffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff08009505a9050610017565b506035806101866000396000f3fe6080604052600080fdfea165627a7a72305820dcaec306f67bb96f3044fff25c9af2ec66f01d0954d0656964f046f42f2780670029".from_hex().unwrap()
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut params = ActionParams::default();
|
|
|
|
params.address = address.clone();
|
|
|
|
params.gas = U256::from(4_000u64);
|
|
|
|
params.code = Some(Arc::new(code.clone()));
|
|
|
|
|
|
|
|
let vm = factory.create(params, ext.schedule(), 0);
|
|
|
|
|
|
|
|
result(vm.exec(&mut ext).ok().unwrap())
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-06 14:22:44 +01:00
|
|
|
fn result(r: Result<evm::GasLeft>) -> U256 {
|
2020-08-05 06:08:03 +02:00
|
|
|
match r {
|
|
|
|
Ok(GasLeft::Known(gas_left)) => gas_left,
|
|
|
|
Ok(GasLeft::NeedsReturn { gas_left, .. }) => gas_left,
|
|
|
|
_ => U256::zero(),
|
|
|
|
}
|
2018-11-06 14:22:44 +01:00
|
|
|
}
|