-
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.
Add crypto & blockchain to fuel-benches (#630)
- Loading branch information
Showing
10 changed files
with
921 additions
and
272 deletions.
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.