-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added price benchmark for
vm_initialization
(#1502)
Closes #1442 --------- Co-authored-by: Brandon Vrooman <[email protected]>
- Loading branch information
Showing
23 changed files
with
222 additions
and
36 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,114 @@ | ||
use criterion::{ | ||
black_box, | ||
Criterion, | ||
Throughput, | ||
}; | ||
use fuel_core_types::{ | ||
fuel_asm::{ | ||
op, | ||
Instruction, | ||
}, | ||
fuel_tx::{ | ||
policies::Policies, | ||
AssetId, | ||
ConsensusParameters, | ||
Input, | ||
Output, | ||
Script, | ||
Transaction, | ||
Word, | ||
}, | ||
fuel_types::canonical::Serialize, | ||
fuel_vm::{ | ||
checked_transaction::{ | ||
Checked, | ||
IntoChecked, | ||
}, | ||
interpreter::NotSupportedEcal, | ||
Interpreter, | ||
}, | ||
}; | ||
use rand::{ | ||
rngs::StdRng, | ||
Rng, | ||
SeedableRng, | ||
}; | ||
|
||
fn transaction<R: Rng>( | ||
rng: &mut R, | ||
script: Vec<u8>, | ||
script_data: Vec<u8>, | ||
consensus_params: &ConsensusParameters, | ||
) -> Checked<Script> { | ||
let inputs = (0..1) | ||
.map(|_| { | ||
Input::coin_predicate( | ||
rng.gen(), | ||
rng.gen(), | ||
rng.gen(), | ||
AssetId::BASE, | ||
rng.gen(), | ||
rng.gen(), | ||
0, | ||
vec![255; 1], | ||
vec![255; 1], | ||
) | ||
}) | ||
.collect(); | ||
|
||
let outputs = (0..1) | ||
.map(|_| { | ||
Output::variable(Default::default(), Default::default(), Default::default()) | ||
}) | ||
.collect(); | ||
|
||
Transaction::script( | ||
1_000_000, | ||
script, | ||
script_data, | ||
Policies::new() | ||
.with_gas_price(0) | ||
.with_maturity(0.into()) | ||
.with_max_fee(Word::MAX), | ||
inputs, | ||
outputs, | ||
vec![vec![123; 32].into(); 1], | ||
) | ||
.into_checked_basic(Default::default(), consensus_params) | ||
.expect("Should produce a valid transaction") | ||
} | ||
|
||
pub fn vm_initialization(c: &mut Criterion) { | ||
let mut rng = StdRng::seed_from_u64(8586); | ||
|
||
let mut group = c.benchmark_group("vm_initialization"); | ||
|
||
let consensus_params = ConsensusParameters::default(); | ||
let mut i = 5usize; | ||
loop { | ||
let size = 8 * (1 << i); | ||
if size as u64 > consensus_params.script_params.max_script_data_length { | ||
break | ||
} | ||
let script = vec![op::ret(1); size / Instruction::SIZE] | ||
.into_iter() | ||
.collect(); | ||
let script_data = vec![255; size]; | ||
let tx = transaction(&mut rng, script, script_data, &consensus_params); | ||
let tx_size = tx.transaction().size(); | ||
let name = format!("vm_initialization_with_tx_size_{}", tx_size); | ||
group.throughput(Throughput::Bytes(tx_size as u64)); | ||
group.bench_function(name, |b| { | ||
b.iter(|| { | ||
let mut vm = black_box( | ||
Interpreter::<_, Script, NotSupportedEcal>::with_memory_storage(), | ||
); | ||
black_box(vm.init_script(tx.clone())) | ||
.expect("Should be able to execute transaction"); | ||
}) | ||
}); | ||
i += 1; | ||
} | ||
|
||
group.finish(); | ||
} |
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
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
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
Oops, something went wrong.