-
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
Add crypto & blockchain to fuel-benches #630
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5b7d6f6
Add crypto & blockchain to fuel-benches
vlopes11 96509af
Unblock I/O failure for blockchain 1m cases
vlopes11 fcb4a33
Run fmt
vlopes11 f22c524
Merge branch 'master' into vlopes11/bench
vlopes11 54c7611
using arc'd tmpfile to fix bal(1M) benchmark (#637)
Voxelot ce27d7c
Merge branch 'master' into vlopes11/bench
Voxelot 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
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
use super::run_group; | ||
|
||
use criterion::Criterion; | ||
use fuel_core_benches::*; | ||
|
||
pub fn run(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("alu"); | ||
|
||
run_group( | ||
&mut group, | ||
"add", | ||
VmBench::new(Opcode::ADD(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"addi", | ||
VmBench::new(Opcode::ADDI(0x10, 0x11, 27)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"and", | ||
VmBench::new(Opcode::AND(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"andi", | ||
VmBench::new(Opcode::ANDI(0x10, 0x11, 27)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"div", | ||
VmBench::new(Opcode::DIV(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"divi", | ||
VmBench::new(Opcode::DIVI(0x10, 0x11, 27)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"eq", | ||
VmBench::new(Opcode::EQ(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"exp", | ||
VmBench::new(Opcode::EXP(0x10, 0x11, 0x12)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 23), Opcode::MOVI(0x12, 11)]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"expi", | ||
VmBench::new(Opcode::EXP(0x10, 0x11, 11)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 23)]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"gt", | ||
VmBench::new(Opcode::GT(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"lt", | ||
VmBench::new(Opcode::LT(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"mlog", | ||
VmBench::new(Opcode::MLOG(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"mod", | ||
VmBench::new(Opcode::MOD(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"modi", | ||
VmBench::new(Opcode::MODI(0x10, 0x11, 27)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"move", | ||
VmBench::new(Opcode::MOVE(0x10, 0x11)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), | ||
); | ||
|
||
run_group(&mut group, "movi", VmBench::new(Opcode::MOVI(0x10, 27))); | ||
|
||
run_group( | ||
&mut group, | ||
"mroo", | ||
VmBench::new(Opcode::MROO(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"mul", | ||
VmBench::new(Opcode::MUL(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"muli", | ||
VmBench::new(Opcode::MULI(0x10, 0x11, 27)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), | ||
); | ||
|
||
run_group(&mut group, "noop", VmBench::new(Opcode::NOOP)); | ||
|
||
run_group( | ||
&mut group, | ||
"not", | ||
VmBench::new(Opcode::NOT(0x10, 0x11)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"or", | ||
VmBench::new(Opcode::OR(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"ori", | ||
VmBench::new(Opcode::ORI(0x10, 0x11, 27)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"sll", | ||
VmBench::new(Opcode::SLL(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"slli", | ||
VmBench::new(Opcode::SLLI(0x10, 0x11, 27)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"srl", | ||
VmBench::new(Opcode::SRL(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"srli", | ||
VmBench::new(Opcode::SRLI(0x10, 0x11, 27)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"sub", | ||
VmBench::new(Opcode::SUB(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"subi", | ||
VmBench::new(Opcode::SUBI(0x10, 0x11, 27)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"xor", | ||
VmBench::new(Opcode::XOR(0x10, 0x11, 0x12)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x11, 100000), | ||
Opcode::MOVI(0x12, 27), | ||
]), | ||
); | ||
|
||
run_group( | ||
&mut group, | ||
"xori", | ||
VmBench::new(Opcode::XORI(0x10, 0x11, 27)) | ||
.with_prepare_script(vec![Opcode::MOVI(0x11, 100000)]), | ||
); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
use super::run_group; | ||
|
||
use criterion::Criterion; | ||
use fuel_core_benches::*; | ||
use rand::{ | ||
rngs::StdRng, | ||
RngCore, | ||
SeedableRng, | ||
}; | ||
|
||
pub fn run(c: &mut Criterion) { | ||
let rng = &mut StdRng::seed_from_u64(2322u64); | ||
|
||
let mut group = c.benchmark_group("blockchain"); | ||
|
||
let cases = vec![1, 10, 100, 1_000, 10_000, 100_000, 1_000_000]; | ||
let asset: AssetId = rng.gen(); | ||
let contract: ContractId = rng.gen(); | ||
|
||
for i in cases.clone() { | ||
run_group( | ||
&mut group, | ||
format!("bal ({})", i), | ||
VmBench::new(Opcode::BAL(0x10, 0x10, 0x11)) | ||
.with_data(asset.iter().chain(contract.iter()).copied().collect()) | ||
.with_prepare_script(vec![ | ||
Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), | ||
Opcode::ADDI(0x11, 0x10, asset.len() as Immediate12), | ||
]) | ||
.with_dummy_contract(contract) | ||
.with_prepare_db(move |mut db| { | ||
let mut asset_inc = AssetId::zeroed(); | ||
|
||
for i in 0..i { | ||
asset_inc.as_mut()[..8] | ||
.copy_from_slice(&(i as u64).to_be_bytes()); | ||
|
||
db.merkle_contract_asset_id_balance_insert( | ||
&contract, &asset_inc, i, | ||
)?; | ||
} | ||
|
||
db.merkle_contract_asset_id_balance_insert(&contract, &asset, 100)?; | ||
|
||
Ok(db) | ||
}), | ||
); | ||
} | ||
|
||
run_group(&mut group, "bhei", VmBench::new(Opcode::BHEI(0x10))); | ||
|
||
run_group( | ||
&mut group, | ||
"bhsh", | ||
VmBench::new(Opcode::BHSH(0x10, REG_ZERO)).with_prepare_script(vec![ | ||
Opcode::MOVI(0x10, Bytes32::LEN as Immediate18), | ||
Opcode::ALOC(0x10), | ||
Opcode::ADDI(0x10, REG_HP, 1), | ||
]), | ||
); | ||
|
||
for i in cases.clone() { | ||
run_group( | ||
&mut group, | ||
format!("sww ({})", i), | ||
VmBench::contract(rng, Opcode::SWW(REG_ZERO, REG_ONE)) | ||
.expect("failed to prepare contract") | ||
.with_prepare_db(move |mut db| { | ||
let mut key = Bytes32::zeroed(); | ||
|
||
for i in 0..i { | ||
key.as_mut()[..8].copy_from_slice(&(i as u64).to_be_bytes()); | ||
|
||
db.merkle_contract_state_insert(&contract, &key, &key)?; | ||
} | ||
|
||
Ok(db) | ||
}), | ||
); | ||
} | ||
|
||
for i in cases { | ||
let mut code = vec![0u8; i as usize]; | ||
|
||
rng.fill_bytes(&mut code); | ||
|
||
let code = ContractCode::from(code); | ||
let id = code.id; | ||
|
||
let data = id | ||
.iter() | ||
.copied() | ||
.chain((0 as Word).to_be_bytes().iter().copied()) | ||
.chain((0 as Word).to_be_bytes().iter().copied()) | ||
.chain(AssetId::default().iter().copied()) | ||
.collect(); | ||
|
||
let prepare_script = vec![ | ||
Opcode::gtf(0x10, 0x00, GTFArgs::ScriptData), | ||
Opcode::ADDI(0x11, 0x10, ContractId::LEN as Immediate12), | ||
Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), | ||
Opcode::ADDI(0x11, 0x11, WORD_SIZE as Immediate12), | ||
Opcode::MOVI(0x12, 100_000), | ||
]; | ||
|
||
run_group( | ||
&mut group, | ||
format!("call ({})", i), | ||
VmBench::new(Opcode::CALL(0x10, REG_ZERO, 0x11, 0x12)) | ||
.with_contract_code(code) | ||
.with_data(data) | ||
.with_prepare_script(prepare_script), | ||
); | ||
} | ||
|
||
group.finish(); | ||
} |
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.
I see this script popping up a lot, could these maybe be moved to a single constant or single expression in case it is ever updated?