-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added price benchmark for vm_initialization
#1502
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3b0ca67
Added price benchmark for `vm_initialization`
xgreenx b205a72
Updated CHANGELOG.md
xgreenx f6d1ac7
Change order
xgreenx c2b83c9
Use `fuel-vm 0.42.1`
xgreenx bbdb283
Make clippy happy
xgreenx 7956f19
dev: update vm initialization benchmark (#1505)
d415340
Make clippy happy
xgreenx f8449cb
Merge branch 'master' into feature/vm-initialisation-benchmark
xgreenx 5de31e9
Replace N with the size check
xgreenx b2c8645
Make clippy happy
xgreenx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,110 @@ | ||
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>, | ||
) -> Checked<Script> { | ||
let consensus_params = ConsensusParameters::default(); | ||
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"); | ||
|
||
// Generate N data points | ||
const N: usize = 18; | ||
for i in 5..N { | ||
let size = 8 * (1 << i); | ||
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); | ||
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"); | ||
}) | ||
}); | ||
} | ||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this
N
come from?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is calculated based on the current script data size limit. I replaced it with the corresponding check instead 5de31e9