Skip to content

Commit

Permalink
"flow" op code sanity benchmarks (#1433)
Browse files Browse the repository at this point in the history
#1386

```
block target estimation/flow/jmp opcode
                        time:   [1.9838 ms 1.9917 ms 2.0001 ms]
block target estimation/flow/ji opcode
                        time:   [1.6020 ms 1.6119 ms 1.6223 ms]
block target estimation/flow/jne opcode
                        time:   [2.2373 ms 2.2479 ms 2.2589 ms]
block target estimation/flow/jnei opcode
                        time:   [2.0990 ms 2.1085 ms 2.1176 ms]
block target estimation/flow/jnzi opcode
                        time:   [1.9626 ms 1.9776 ms 1.9930 ms]
block target estimation/flow/jmpb opcode
                        time:   [1.5740 ms 1.5819 ms 1.5904 ms]
block target estimation/flow/jmpf opcode
                        time:   [1.5385 ms 1.5455 ms 1.5529 ms]
block target estimation/flow/jnzb opcode true
                        time:   [1.6174 ms 1.6246 ms 1.6323 ms]
block target estimation/flow/jnzb opcode false
                        time:   [1.6395 ms 1.6482 ms 1.6568 ms]
block target estimation/flow/jnzf opcode true
                        time:   [1.5932 ms 1.5999 ms 1.6070 ms]
block target estimation/flow/jnzf opcode false
                        time:   [1.6132 ms 1.6227 ms 1.6333 ms]
block target estimation/flow/jne opcode
                        time:   [1.7591 ms 1.7703 ms 1.7822 ms]
block target estimation/flow/jnei opcode
                        time:   [1.5247 ms 1.5340 ms 1.5447 ms]
block target estimation/flow/jneb opcode not equal
                        time:   [1.6881 ms 1.6961 ms 1.7057 ms]
block target estimation/flow/jneb opcode equal
                        time:   [1.7255 ms 1.7362 ms 1.7481 ms]
block target estimation/flow/jnef opcode not equal
                        time:   [1.8018 ms 1.8132 ms 1.8259 ms]
block target estimation/flow/jnef opcode equal
                        time:   [1.7644 ms 1.7731 ms 1.7823 ms]
```

Not sure how to test `ret_script` or `ret_contract` with an infinite
loop 🤷

---------

Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
  • Loading branch information
MitchTurner and xgreenx authored Oct 24, 2023
1 parent fd9bb60 commit 17093e0
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions benches/benches/block_target_gas.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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();
}

Expand Down
20 changes: 20 additions & 0 deletions benches/benches/block_target_gas_set/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::*;
// use crate::utils::arb_dependent_cost_values;

pub fn run_contract(_group: &mut BenchmarkGroup<WallTime>) {
// 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![],
// );
// }
}
6 changes: 3 additions & 3 deletions benches/benches/block_target_gas_set/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
utils::generate_linear_costs,
utils::arb_dependent_cost_values,
*,
};
use rand::{
Expand Down Expand Up @@ -135,7 +135,7 @@ pub fn run_crypto(group: &mut BenchmarkGroup<WallTime>) {
.collect(),
);

for i in generate_linear_costs() {
for i in arb_dependent_cost_values() {
let id = format!("crypto/s256 opcode {:?}", i);
run(
&id,
Expand All @@ -152,7 +152,7 @@ pub fn run_crypto(group: &mut BenchmarkGroup<WallTime>) {
)
}

for i in generate_linear_costs() {
for i in arb_dependent_cost_values() {
let id = format!("crypto/k256 opcode {:?}", i);
run(
&id,
Expand Down
188 changes: 188 additions & 0 deletions benches/benches/block_target_gas_set/flow.rs
Original file line number Diff line number Diff line change
@@ -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<WallTime>) {
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![],
// );
}
4 changes: 4 additions & 0 deletions benches/benches/block_target_gas_set/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pub mod alu;

pub mod crypto;

pub mod flow;

pub mod contract;
2 changes: 1 addition & 1 deletion benches/benches/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn make_u256(reg: u8, v: U256) -> Vec<Instruction> {
aloc_bytearray(reg, v.to_be_bytes())
}

pub fn generate_linear_costs() -> Vec<u32> {
pub fn arb_dependent_cost_values() -> Vec<u32> {
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)
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/vm_set/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 3 additions & 10 deletions benches/benches/vm_set/flow.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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::<Vec<_>>();
l.sort_unstable();
linear.extend(l);
let linear = arb_dependent_cost_values();

run_group_ref(
&mut c.benchmark_group("jmp"),
Expand Down
4 changes: 2 additions & 2 deletions benches/benches/vm_set/mem.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 17093e0

Please sign in to comment.