2020-01-17 14:27:28 +01:00
|
|
|
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
2020-03-05 12:19:39 +01:00
|
|
|
// This file is part of Open Ethereum.
|
2016-07-12 09:49:16 +02:00
|
|
|
|
2020-03-05 12:19:39 +01:00
|
|
|
// Open Ethereum is free software: you can redistribute it and/or modify
|
2016-07-12 09:49:16 +02: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-03-05 12:19:39 +01:00
|
|
|
// Open Ethereum is distributed in the hope that it will be useful,
|
2016-07-12 09:49:16 +02: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-03-05 12:19:39 +01:00
|
|
|
// along with Open Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2016-07-12 09:49:16 +02:00
|
|
|
|
|
|
|
//! benchmarking for EVM
|
|
|
|
//! should be started with:
|
|
|
|
//! ```bash
|
2019-09-05 19:28:01 +02:00
|
|
|
//! cargo bench
|
2016-07-12 09:49:16 +02:00
|
|
|
//! ```
|
|
|
|
|
2019-09-05 19:28:01 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate criterion;
|
2020-02-21 15:10:00 +01:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate hex_literal;
|
|
|
|
|
2016-07-12 09:49:16 +02:00
|
|
|
extern crate ethcore;
|
|
|
|
extern crate evm;
|
2019-04-12 09:49:39 +02:00
|
|
|
extern crate ethereum_types;
|
|
|
|
extern crate vm;
|
2016-07-12 09:49:16 +02:00
|
|
|
|
2019-04-12 09:49:39 +02:00
|
|
|
use std::sync::Arc;
|
2019-09-05 19:28:01 +02:00
|
|
|
use criterion::{Criterion, black_box};
|
2016-07-12 09:49:16 +02:00
|
|
|
|
2019-04-12 09:49:39 +02:00
|
|
|
use ethereum_types::U256;
|
|
|
|
use evm::Factory;
|
|
|
|
use vm::tests::FakeExt;
|
|
|
|
use vm::{ActionParams, Ext};
|
2016-07-12 09:49:16 +02:00
|
|
|
|
2019-09-05 19:28:01 +02:00
|
|
|
criterion_group!(
|
|
|
|
evmbin,
|
|
|
|
bench_simple_loop_usize,
|
|
|
|
bench_simple_loop_u256,
|
|
|
|
bench_rng_usize,
|
|
|
|
bench_rng_u256
|
|
|
|
);
|
|
|
|
criterion_main!(evmbin);
|
|
|
|
|
|
|
|
fn bench_simple_loop_usize(c: &mut Criterion) {
|
|
|
|
simple_loop(U256::from(::std::usize::MAX), c, "simple_loop_usize")
|
2016-07-12 09:49:16 +02:00
|
|
|
}
|
|
|
|
|
2019-09-05 19:28:01 +02:00
|
|
|
fn bench_simple_loop_u256(c: &mut Criterion) {
|
|
|
|
simple_loop(!U256::zero(), c, "simple_loop_u256")
|
2016-07-12 09:49:16 +02:00
|
|
|
}
|
|
|
|
|
2019-09-05 19:28:01 +02:00
|
|
|
fn simple_loop(gas: U256, c: &mut Criterion, bench_id: &str) {
|
2016-07-12 09:49:16 +02:00
|
|
|
let code = black_box(
|
2020-02-21 15:10:00 +01:00
|
|
|
hex!("606060405260005b620042408112156019575b6001016007565b600081905550600680602b6000396000f3606060405200").to_vec()
|
2016-07-12 09:49:16 +02:00
|
|
|
);
|
|
|
|
|
2019-09-05 19:28:01 +02:00
|
|
|
c.bench_function(bench_id, move |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let mut params = ActionParams::default();
|
|
|
|
params.gas = gas;
|
|
|
|
params.code = Some(Arc::new(code.clone()));
|
2016-07-12 09:49:16 +02:00
|
|
|
|
2019-09-05 19:28:01 +02:00
|
|
|
let mut ext = FakeExt::new();
|
|
|
|
let evm = Factory::default().create(params, ext.schedule(), ext.depth());
|
|
|
|
let _ = evm.exec(&mut ext);
|
|
|
|
})
|
2016-07-12 09:49:16 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-05 19:28:01 +02:00
|
|
|
fn bench_rng_usize(c: &mut Criterion) {
|
|
|
|
rng(U256::from(::std::usize::MAX), c, "rng_usize")
|
2016-07-12 09:49:16 +02:00
|
|
|
}
|
|
|
|
|
2019-09-05 19:28:01 +02:00
|
|
|
fn bench_rng_u256(c: &mut Criterion) {
|
|
|
|
rng(!U256::zero(), c, "rng_u256")
|
2016-07-12 09:49:16 +02:00
|
|
|
}
|
|
|
|
|
2019-09-05 19:28:01 +02:00
|
|
|
fn rng(gas: U256, c: &mut Criterion, bench_id: &str) {
|
2016-07-12 09:49:16 +02:00
|
|
|
let code = black_box(
|
2020-02-21 15:10:00 +01:00
|
|
|
hex!("6060604052600360056007600b60005b62004240811215607f5767ffe7649d5eca84179490940267f47ed85c4b9a6379019367f8e5dd9a5c994bba9390930267f91d87e4b8b74e55019267ff97f6f3b29cda529290920267f393ada8dd75c938019167fe8d437c45bb3735830267f47d9a7b5428ffec019150600101600f565b838518831882186000555050505050600680609a6000396000f3606060405200").to_vec()
|
2016-07-12 09:49:16 +02:00
|
|
|
);
|
|
|
|
|
2019-09-05 19:28:01 +02:00
|
|
|
c.bench_function(bench_id, move |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let mut params = ActionParams::default();
|
|
|
|
params.gas = gas;
|
|
|
|
params.code = Some(Arc::new(code.clone()));
|
2016-07-12 09:49:16 +02:00
|
|
|
|
2019-09-05 19:28:01 +02:00
|
|
|
let mut ext = FakeExt::new();
|
|
|
|
let evm = Factory::default().create(params, ext.schedule(), ext.depth());
|
|
|
|
let _ = evm.exec(&mut ext);
|
|
|
|
})
|
2016-07-12 09:49:16 +02:00
|
|
|
});
|
|
|
|
}
|