diff --git a/CHANGELOG.md b/CHANGELOG.md index b5d5ebfc11d..50ca106fd1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ Description of the upcoming release here. ### Added +- [#1433](https://github.com/FuelLabs/fuel-core/pull/1433): Add "sanity" benchmarks for flow opcodes +- [#1430](https://github.com/FuelLabs/fuel-core/pull/1430): Add "sanity" benchmarks for crypto opcodes - [#1436](https://github.com/FuelLabs/fuel-core/pull/1436): Add a github action to continuously test beta-4. - [#1430](https://github.com/FuelLabs/fuel-core/pull/1430): Add "sanity" benchmarks for crypto opcodes. - [#1437](https://github.com/FuelLabs/fuel-core/pull/1437): Add some transaction throughput tests for basic transfers. diff --git a/benches/benches/block_target_gas.rs b/benches/benches/block_target_gas.rs index e2de497ec83..b499b0ccb0e 100644 --- a/benches/benches/block_target_gas.rs +++ b/benches/benches/block_target_gas.rs @@ -1,6 +1,8 @@ use block_target_gas_set::{ alu::run_alu, + contract::run_contract, crypto::run_crypto, + flow::run_flow, }; use criterion::{ criterion_group, @@ -175,8 +177,12 @@ fn block_target_gas(c: &mut Criterion) { run_alu(&mut group); + run_contract(&mut group); + run_crypto(&mut group); + run_flow(&mut group); + group.finish(); } diff --git a/benches/benches/block_target_gas_set/contract.rs b/benches/benches/block_target_gas_set/contract.rs new file mode 100644 index 00000000000..2f84f85fb94 --- /dev/null +++ b/benches/benches/block_target_gas_set/contract.rs @@ -0,0 +1,20 @@ +use crate::*; +// use crate::utils::arb_dependent_cost_values; + +pub fn run_contract(_group: &mut BenchmarkGroup) { + // This breaks the benchmarking + // for i in arb_dependent_cost_values() { + // let id = format!("flow/retd_contract opcode {:?}", i); + // run( + // &id, + // group, + // vec![ + // op::movi(0x10, i), + // op::retd(RegId::ONE, 0x10), + // op::jmpb(RegId::ZERO, 0), + // ] + // .to_vec(), + // vec![], + // ); + // } +} diff --git a/benches/benches/block_target_gas_set/crypto.rs b/benches/benches/block_target_gas_set/crypto.rs index c94598e0ee0..034f69843fd 100644 --- a/benches/benches/block_target_gas_set/crypto.rs +++ b/benches/benches/block_target_gas_set/crypto.rs @@ -1,5 +1,5 @@ use crate::{ - utils::generate_linear_costs, + utils::arb_dependent_cost_values, *, }; use rand::{ @@ -135,7 +135,7 @@ pub fn run_crypto(group: &mut BenchmarkGroup) { .collect(), ); - for i in generate_linear_costs() { + for i in arb_dependent_cost_values() { let id = format!("crypto/s256 opcode {:?}", i); run( &id, @@ -152,7 +152,7 @@ pub fn run_crypto(group: &mut BenchmarkGroup) { ) } - for i in generate_linear_costs() { + for i in arb_dependent_cost_values() { let id = format!("crypto/k256 opcode {:?}", i); run( &id, diff --git a/benches/benches/block_target_gas_set/flow.rs b/benches/benches/block_target_gas_set/flow.rs new file mode 100644 index 00000000000..8e1cff134ed --- /dev/null +++ b/benches/benches/block_target_gas_set/flow.rs @@ -0,0 +1,188 @@ +use crate::*; + +// JMP: Jump +// JI: Jump immediate +// JNE: Jump if not equal +// JNEI: Jump if not equal immediate +// JNZI: Jump if not zero immediate +// JMPB: Jump relative backwards +// JMPF: Jump relative forwards +// JNZB: Jump if not zero relative backwards +// JNZF: Jump if not zero relative forwards +// JNEB: Jump if not equal relative backwards +// JNEF: Jump if not equal relative forwards +// RET: Return from context +pub fn run_flow(group: &mut BenchmarkGroup) { + run( + "flow/jmp opcode", + group, + vec![op::movi(0x10, 0), op::jmp(0x10)], + vec![], + ); + + run( + "flow/ji opcode", + group, + vec![op::ji(0), op::jmpb(RegId::ZERO, 0)], + vec![], + ); + + run( + "flow/jne opcode", + group, + vec![ + op::movi(0x10, 0), + op::jne(RegId::ZERO, RegId::ONE, 0x10), + op::jmpb(RegId::ZERO, 0), + ], + vec![], + ); + + run( + "flow/jnei opcode", + group, + vec![ + op::jnei(RegId::ZERO, RegId::ONE, 0), + op::jmpb(RegId::ZERO, 0), + ], + vec![], + ); + + run( + "flow/jnzi opcode", + group, + vec![op::jnzi(RegId::ONE, 0), op::jmpb(RegId::ZERO, 0)], + vec![], + ); + + run( + "flow/jmpb opcode", + group, + vec![op::noop(), op::jmpb(RegId::ZERO, 0)], + vec![], + ); + + run( + "flow/jmpf opcode", + group, + vec![op::jmpf(RegId::ZERO, 0), op::jmpb(RegId::ZERO, 0)], + vec![], + ); + + run( + "flow/jnzb opcode true", + group, + vec![ + op::movi(0x10, 1), + op::noop(), + op::jnzb(0x10, RegId::ZERO, 0), + ], + vec![], + ); + + run( + "flow/jnzb opcode false", + group, + vec![ + op::movi(0x10, 0), + op::noop(), + op::jnzb(0x10, RegId::ZERO, 0), + op::jmpb(RegId::ZERO, 0), + ], + vec![], + ); + + run( + "flow/jnzf opcode true", + group, + vec![ + op::movi(0x10, 1), + op::noop(), + op::jnzf(0x10, RegId::ZERO, 1), + op::ret(RegId::ZERO), + op::jmpb(RegId::ZERO, 1), + ], + vec![], + ); + + run( + "flow/jnzf opcode false", + group, + vec![ + op::movi(0x10, 0), + op::noop(), + op::jnzf(0x10, RegId::ZERO, 1), + op::jmpb(RegId::ZERO, 0), + op::noop(), + ], + vec![], + ); + + run( + "flow/jneb opcode not equal", + group, + vec![ + op::movi(0x10, 1), + op::movi(0x11, 0), + op::noop(), + op::jneb(0x10, 0x11, RegId::ZERO, 0), + ], + vec![], + ); + + run( + "flow/jneb opcode equal", + group, + vec![ + op::movi(0x10, 1), + op::movi(0x11, 1), + op::noop(), + op::jneb(0x10, 0x11, RegId::ZERO, 0), + op::jmpb(RegId::ZERO, 0), + ], + vec![], + ); + + run( + "flow/jnef opcode not equal", + group, + vec![ + op::movi(0x10, 1), + op::movi(0x11, 0), + op::noop(), + op::jnef(0x10, 0x11, RegId::ZERO, 1), + op::ret(RegId::ZERO), + op::jmpb(RegId::ZERO, 1), + ], + vec![], + ); + + run( + "flow/jnef opcode equal", + group, + vec![ + op::movi(0x10, 1), + op::movi(0x11, 1), + op::noop(), + op::jnef(0x10, 0x11, RegId::ZERO, 1), + op::jmpb(RegId::ZERO, 0), + op::noop(), + ], + vec![], + ); + + // Don't know how to test "returning" op codes + // run( + // "flow/ret_script opcode", + // group, + // vec![op::ret(RegId::ONE), op::jmpb(RegId::ZERO, 0)].to_vec(), + // vec![], + // ); + // + // run( + // "flow/ret_contract opcode", + // group, + // vec![op::ret(RegId::ONE), op::jmpb(RegId::ZERO, 0)].to_vec(), + // vec![], + // ); +} diff --git a/benches/benches/block_target_gas_set/mod.rs b/benches/benches/block_target_gas_set/mod.rs index cae18be40ce..7528fe6cf6a 100644 --- a/benches/benches/block_target_gas_set/mod.rs +++ b/benches/benches/block_target_gas_set/mod.rs @@ -1,3 +1,7 @@ pub mod alu; pub mod crypto; + +pub mod flow; + +pub mod contract; diff --git a/benches/benches/utils.rs b/benches/benches/utils.rs index 3ebc5321b04..58f9f9f5abb 100644 --- a/benches/benches/utils.rs +++ b/benches/benches/utils.rs @@ -27,7 +27,7 @@ pub fn make_u256(reg: u8, v: U256) -> Vec { aloc_bytearray(reg, v.to_be_bytes()) } -pub fn generate_linear_costs() -> Vec { +pub fn arb_dependent_cost_values() -> Vec { let mut linear = vec![1, 10, 100, 1000, 10_000]; let mut l = successors(Some(100_000.0f64), |n| Some(n / 1.5)) .take(5) diff --git a/benches/benches/vm_set/crypto.rs b/benches/benches/vm_set/crypto.rs index 19c59a61a35..46d75433d85 100644 --- a/benches/benches/vm_set/crypto.rs +++ b/benches/benches/vm_set/crypto.rs @@ -73,7 +73,7 @@ pub fn run(c: &mut Criterion) { ), ); - let linear = super::utils::generate_linear_costs(); + let linear = super::utils::arb_dependent_cost_values(); let mut bench_k256 = c.benchmark_group("k256"); for i in &linear { diff --git a/benches/benches/vm_set/flow.rs b/benches/benches/vm_set/flow.rs index ceb096754c5..9f88e7f9b3a 100644 --- a/benches/benches/vm_set/flow.rs +++ b/benches/benches/vm_set/flow.rs @@ -1,12 +1,11 @@ -use std::iter::successors; - use super::run_group_ref; +use crate::utils::arb_dependent_cost_values; use criterion::{ Criterion, Throughput, }; -use fuel_core_benches::*; +use fuel_core_benches::VmBench; use fuel_core_types::fuel_asm::*; use rand::{ rngs::StdRng, @@ -16,13 +15,7 @@ use rand::{ pub fn run(c: &mut Criterion) { let rng = &mut StdRng::seed_from_u64(2322u64); - let mut linear = vec![1, 10, 100, 1000, 10_000]; - let mut l = successors(Some(100_000.0f64), |n| Some(n / 1.5)) - .take(5) - .map(|f| f as u32) - .collect::>(); - l.sort_unstable(); - linear.extend(l); + let linear = arb_dependent_cost_values(); run_group_ref( &mut c.benchmark_group("jmp"), diff --git a/benches/benches/vm_set/mem.rs b/benches/benches/vm_set/mem.rs index 0b4c6b713cb..f6af7ec588d 100644 --- a/benches/benches/vm_set/mem.rs +++ b/benches/benches/vm_set/mem.rs @@ -1,6 +1,6 @@ use super::run_group_ref; -use crate::utils::generate_linear_costs; +use crate::utils::arb_dependent_cost_values; use criterion::{ Criterion, Throughput, @@ -54,7 +54,7 @@ pub fn run(c: &mut Criterion) { ]), ); - let linear = generate_linear_costs(); + let linear = arb_dependent_cost_values(); run_group_ref( &mut c.benchmark_group("cfei"),