-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
354 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::time::Duration; | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use revm::primitives::Address; | ||
use tinyevm::{fn_sig_to_prefix, UZERO}; | ||
|
||
const OWNER: Address = Address::repeat_byte(0x01); | ||
const DEPLOY_TO_ADDRESS: Address = Address::repeat_byte(0x02); | ||
|
||
#[allow(unused)] | ||
fn bench_call_complex_function(c: &mut Criterion) { | ||
c.bench_function("call_complex_function", |b| { | ||
let source = include_str!("../tests/contracts/complex_contract.hex"); | ||
let bytecode = hex::decode(source).unwrap(); | ||
let mut exe = tinyevm::TinyEVM::default(); | ||
let owner = OWNER; | ||
let deploy_to_address = Some(DEPLOY_TO_ADDRESS); | ||
|
||
let resp = { | ||
exe.deploy_helper(owner, bytecode, UZERO, None, deploy_to_address) | ||
.unwrap() | ||
}; | ||
|
||
assert!(resp.success, "Contract deploy should succeed."); | ||
let address = Address::from_slice(&resp.data); | ||
|
||
let fn_sig = "complexFunction()"; | ||
b.iter(|| { | ||
let data = hex::decode(fn_sig_to_prefix(fn_sig)).unwrap(); | ||
|
||
let r = exe.contract_call_helper(address, owner, data, UZERO, None); | ||
// assert!(r.success); // this function can revert sometimes | ||
assert!(r.gas_usage > 0); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!( | ||
name = complex; | ||
config = Criterion::default().measurement_time(Duration::from_secs(10)); | ||
targets = bench_call_complex_function, | ||
); | ||
|
||
criterion_main!(complex); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use primitive_types::H256; | ||
use revm::primitives::Address; | ||
use ruint::aliases::U256; | ||
use tinyevm::{TinyEVM, UZERO}; | ||
|
||
const OWNER: Address = Address::repeat_byte(0x01); | ||
const DEPLOY_TO_ADDRESS: Address = Address::repeat_byte(0x02); | ||
|
||
// Reusing can be slower because there are more data inside the instrumentation log | ||
fn bench_contract_deterministic_deploy(c: &mut Criterion) { | ||
c.bench_function("deploy_contract_deterministic", |b| { | ||
let source = include_str!("../tests/contracts/calls_trace.hex"); | ||
let source = hex::decode(source).unwrap(); | ||
let mut exe = TinyEVM::default(); | ||
|
||
b.iter(|| { | ||
{ | ||
exe.deploy_helper(OWNER, source.clone(), UZERO, None, Some(DEPLOY_TO_ADDRESS)) | ||
.unwrap(); | ||
}; | ||
}) | ||
}); | ||
} | ||
|
||
fn bench_contract_deploy_on_different_executors(c: &mut Criterion) { | ||
c.bench_function("deploy_contract_deploy_on_different_executors", |b| { | ||
let source = include_str!("../tests/contracts/calls_trace.hex"); | ||
let source = hex::decode(source).unwrap(); | ||
|
||
b.iter(|| { | ||
let mut exe = TinyEVM::default(); | ||
{ | ||
exe.deploy_helper( | ||
OWNER, | ||
source.clone(), | ||
U256::from(0), | ||
None, | ||
Some(DEPLOY_TO_ADDRESS), | ||
) | ||
.unwrap(); | ||
}; | ||
}) | ||
}); | ||
} | ||
|
||
#[allow(unused)] | ||
fn bench_random_h256(c: &mut Criterion) { | ||
c.bench_function("call H256 random", |b| { | ||
b.iter(|| { | ||
let _ = H256::random(); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!( | ||
name = deploy; | ||
config = Criterion::default(); | ||
targets = bench_random_h256, bench_contract_deterministic_deploy, bench_contract_deploy_on_different_executors | ||
); | ||
|
||
criterion_main!(deploy); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use std::{iter::repeat_with, time::Duration}; | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use primitive_types::H256; | ||
use revm::primitives::Address; | ||
use tinyevm::{fn_sig_to_prefix, TinyEVM, UZERO}; | ||
|
||
const OWNER: Address = Address::repeat_byte(0x01); | ||
const DEPLOY_TO_ADDRESS: Address = Address::repeat_byte(0x02); | ||
|
||
#[allow(unused)] | ||
fn bench_call_function_returning_large_string(c: &mut Criterion) { | ||
c.bench_function("call_function_returning_large_string", |b| { | ||
let source = include_str!("../tests/contracts/VeLogo.hex"); | ||
let bytecode = hex::decode(source).unwrap(); | ||
let mut exe = TinyEVM::default(); | ||
|
||
let resp = { | ||
exe.deploy_helper(OWNER, bytecode, UZERO, None, Some(DEPLOY_TO_ADDRESS)) | ||
.unwrap() | ||
}; | ||
|
||
assert!(resp.success, "Contract deploy should succeed."); | ||
let address = Address::from_slice(&resp.data); | ||
|
||
let fn_sig = "tokenURI(uint256,uint256,uint256,uint256)"; | ||
b.iter(|| { | ||
let fn_args_hex: String = repeat_with(H256::random).take(4).map(hex::encode).collect(); | ||
|
||
let add_hex = format!("{}{}", fn_sig_to_prefix(fn_sig), fn_args_hex); | ||
|
||
let data = hex::decode(add_hex).unwrap(); | ||
|
||
let r = exe.contract_call_helper(address, OWNER, data, UZERO, None); | ||
assert!(r.success); | ||
}) | ||
}); | ||
} | ||
|
||
#[allow(unused)] | ||
// TODO this repeats most part of the previous test function, refactor | ||
fn bench_call_function_returning_large_string_no_instrumentation(c: &mut Criterion) { | ||
c.bench_function( | ||
"call_function_returning_large_string_no_instrumetation", | ||
|b| { | ||
let source = include_str!("../tests/contracts/VeLogo.hex"); | ||
let bytecode = hex::decode(source).unwrap(); | ||
let mut exe = TinyEVM::default(); | ||
exe.instrument_config_mut().enabled = false; | ||
|
||
let resp = { | ||
exe.deploy_helper(OWNER, bytecode, UZERO, None, Some(DEPLOY_TO_ADDRESS)) | ||
.unwrap() | ||
}; | ||
|
||
assert!(resp.success, "Contract deploy should succeed."); | ||
let address = Address::from_slice(&resp.data); | ||
|
||
let fn_sig = "tokenURI(uint256,uint256,uint256,uint256)"; | ||
b.iter(|| { | ||
let fn_args_hex: String = | ||
repeat_with(H256::random).take(4).map(hex::encode).collect(); | ||
|
||
let add_hex = format!("{}{}", fn_sig_to_prefix(fn_sig), fn_args_hex); | ||
|
||
let data = hex::decode(add_hex).unwrap(); | ||
|
||
let r = exe.contract_call_helper(address, OWNER, data, UZERO, None); | ||
assert!(r.success); | ||
}) | ||
}, | ||
); | ||
} | ||
|
||
criterion_group!( | ||
name = evm_benches; | ||
config = Criterion::default().measurement_time(Duration::from_secs(10)); | ||
targets = bench_call_function_returning_large_string, | ||
bench_call_function_returning_large_string_no_instrumentation, | ||
); | ||
|
||
criterion_main!(evm_benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use revm::primitives::Address; | ||
use tinyevm::{fn_sig_to_prefix, TinyEVM, UZERO}; | ||
|
||
const OWNER: Address = Address::repeat_byte(0x01); | ||
const DEPLOY_TO_ADDRESS: Address = Address::repeat_byte(0x02); | ||
|
||
#[allow(unused)] | ||
fn bench_call_tracing_with_shared_executor(c: &mut Criterion) { | ||
c.bench_function("call_tracing_with_shared_executor", |b| { | ||
let source = include_str!("../tests/contracts/calls_trace.hex"); | ||
let bytecode = hex::decode(source).unwrap(); | ||
let fn_sig = "test_call_success_success_failed()"; | ||
let fn_args_hex = ""; | ||
let add_hex = format!("{}{}", fn_sig_to_prefix(fn_sig), fn_args_hex); | ||
|
||
let data = hex::decode(add_hex).unwrap(); | ||
let mut exe = TinyEVM::default(); | ||
|
||
let resp = { | ||
exe.deploy_helper(OWNER, bytecode, UZERO, None, Some(DEPLOY_TO_ADDRESS)) | ||
.unwrap() | ||
}; | ||
|
||
assert!(resp.success, "Contract deploy should succeed."); | ||
let address = Address::from_slice(&resp.data); | ||
|
||
b.iter(|| { | ||
let _ = exe.contract_call_helper(address, OWNER, data.clone(), UZERO, None); | ||
}) | ||
}); | ||
} | ||
|
||
#[allow(unused)] | ||
fn bench_call_tracing_with_different_executor(c: &mut Criterion) { | ||
c.bench_function("call_tracing_with_different_executor", |b| { | ||
let source = include_str!("../tests/contracts/calls_trace.hex"); | ||
let bytecode = hex::decode(source).unwrap(); | ||
let fn_sig = "test_call_success_success_failed()"; | ||
let fn_args_hex = ""; | ||
let add_hex = format!("{}{}", fn_sig_to_prefix(fn_sig), fn_args_hex); | ||
|
||
let data = hex::decode(add_hex).unwrap(); | ||
b.iter(|| { | ||
let mut exe = TinyEVM::default(); | ||
let resp = exe | ||
.deploy_helper( | ||
OWNER, | ||
bytecode.clone(), | ||
UZERO, | ||
None, | ||
Some(DEPLOY_TO_ADDRESS), | ||
) | ||
.unwrap(); | ||
|
||
let address = Address::from_slice(&resp.data); | ||
|
||
let _ = exe.contract_call_helper(address, OWNER, data.clone(), UZERO, None); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!( | ||
name = evm_benches; | ||
config = Criterion::default(); | ||
targets = bench_call_tracing_with_shared_executor, bench_call_tracing_with_different_executor | ||
); | ||
|
||
criterion_main!(evm_benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use primitive_types::{H160, U256}; | ||
use revm::primitives::Address; | ||
use tinyevm::{fn_sig_to_prefix, TinyEVM, UZERO}; | ||
|
||
const OWNER: Address = Address::repeat_byte(0x01); | ||
const DEPLOY_TO_ADDRESS: Address = Address::repeat_byte(0x02); | ||
|
||
// ~100ms per loop | ||
fn bench_infinite_loop_math(c: &mut Criterion) { | ||
c.bench_function("infinite_loop_with_simple_math", |b| { | ||
let source = include_str!("../tests/contracts/infinite_loop_Test2.hex"); | ||
let bytecode = hex::decode(source).unwrap(); | ||
let fn_sig = "test1(int256)"; | ||
let fn_args_hex = format!("{:0>64x}", U256::from(0)); | ||
let add_hex = format!("{}{}", fn_sig_to_prefix(fn_sig), fn_args_hex); | ||
|
||
let data = hex::decode(add_hex).unwrap(); | ||
let mut exe = TinyEVM::default(); | ||
|
||
let resp = { | ||
exe.deploy_helper(OWNER, bytecode, UZERO, None, Some(DEPLOY_TO_ADDRESS)) | ||
.unwrap() | ||
}; | ||
|
||
assert!(resp.success, "Contract deploy should succeed."); | ||
let address = Address::from_slice(&resp.data); | ||
|
||
b.iter(|| { | ||
let _ = exe.contract_call_helper(address, OWNER, data.clone(), UZERO, None); | ||
}) | ||
}); | ||
} | ||
|
||
// <300ms per loop | ||
fn bench_infinite_loop_adderss_call(c: &mut Criterion) { | ||
c.bench_function("infinite_loop_with_address_call", |b| { | ||
let source = include_str!("../tests/contracts/infinite_loop_Test.hex"); | ||
let bytecode = hex::decode(source).unwrap(); | ||
let fn_sig = "test1(int256)"; | ||
let fn_args_hex = format!("{:0>64x}", U256::from(0)); | ||
let add_hex = format!("{}{}", fn_sig_to_prefix(fn_sig), fn_args_hex); | ||
|
||
let data = hex::decode(add_hex).unwrap(); | ||
let mut exe = TinyEVM::default(); | ||
|
||
let resp = { | ||
exe.deploy_helper(OWNER, bytecode, UZERO, None, Some(DEPLOY_TO_ADDRESS)) | ||
.unwrap() | ||
}; | ||
|
||
assert!(resp.success, "Contract deploy should succeed."); | ||
let address = Address::from_slice(&resp.data); | ||
|
||
b.iter(|| { | ||
let _ = exe.contract_call_helper(address, OWNER, data.clone(), UZERO, None); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!( | ||
name = infinite_loop; | ||
config = Criterion::default(); | ||
targets = bench_infinite_loop_math, bench_infinite_loop_adderss_call | ||
); | ||
|
||
criterion_main!(infinite_loop); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters