Skip to content

Commit

Permalink
Benchmark {k256, s256, mcpi} opcodes using DependentCost (FuelLabs#1395)
Browse files Browse the repository at this point in the history
Closes FuelLabs#1325

---------

Co-authored-by: Green Baneling <[email protected]>
  • Loading branch information
Dentosal and xgreenx authored Oct 5, 2023
1 parent 7196116 commit 9117a22
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 53 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Description of the upcoming release here.
- [#1390](https://github.com/FuelLabs/fuel-core/pull/1390): Up the `ethers` version to `2` to fix an issue with `tungstenite`.
- [#1392](https://github.com/FuelLabs/fuel-core/pull/1392): Fixed an overflow in `message_proof`.
- [#1393](https://github.com/FuelLabs/fuel-core/pull/1393): Increase heartbeat timeout from `2` to `60` seconds, as suggested in [this issue](https://github.com/FuelLabs/fuel-core/issues/1330).
- [#1395](https://github.com/FuelLabs/fuel-core/pull/1395): Add DependentCost benchmarks for `k256`, `s256` and `mcpi` instructions.

#### Breaking
- [#1374](https://github.com/FuelLabs/fuel-core/pull/1374): Renamed `base_chain_height` to `da_height` and return current relayer height instead of latest Fuel block height.
Expand Down
62 changes: 28 additions & 34 deletions benches/benches/set/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use super::run_group_ref;

use criterion::Criterion;
use criterion::{
Criterion,
Throughput,
};
use ed25519_dalek::Signer;
use fuel_core_benches::*;
use fuel_core_types::{
fuel_asm::*,
fuel_crypto::*,
fuel_types::*,
};
use rand::{
rngs::StdRng,
Expand Down Expand Up @@ -71,41 +73,33 @@ pub fn run(c: &mut Criterion) {
),
);

run_group_ref(
&mut c.benchmark_group("k256"),
"k256",
VmBench::new(op::k256(RegId::HP, RegId::ZERO, 0x11))
.with_prepare_script(vec![
op::movi(0x10, Bytes32::LEN.try_into().unwrap()),
op::aloc(0x10),
op::movi(0x11, 32),
])
.with_data(
eck1_signature
.iter()
.chain(message.iter())
.copied()
.collect(),
let linear = super::generate_linear_costs();

let mut bench_k256 = c.benchmark_group("k256");
for i in &linear {
bench_k256.throughput(Throughput::Bytes(*i as u64));
run_group_ref(
&mut bench_k256,
format!("{i}"),
VmBench::new(op::k256(RegId::HP, RegId::ZERO, 0x10)).with_prepare_script(
vec![op::movi(0x11, 32), op::aloc(0x11), op::movi(0x10, *i)],
),
);
);
}
bench_k256.finish();

run_group_ref(
&mut c.benchmark_group("s256"),
"s256",
VmBench::new(op::s256(RegId::HP, RegId::ZERO, 0x11))
.with_prepare_script(vec![
op::movi(0x10, Bytes32::LEN.try_into().unwrap()),
op::aloc(0x10),
op::movi(0x11, 32),
])
.with_data(
eck1_signature
.iter()
.chain(message.iter())
.copied()
.collect(),
let mut bench_s256 = c.benchmark_group("s256");
for i in &linear {
bench_s256.throughput(Throughput::Bytes(*i as u64));
run_group_ref(
&mut bench_s256,
format!("{i}"),
VmBench::new(op::s256(RegId::HP, RegId::ZERO, 0x10)).with_prepare_script(
vec![op::movi(0x11, 32), op::aloc(0x11), op::movi(0x10, *i)],
),
);
);
}
bench_s256.finish();

let ed19_keypair =
ed25519_dalek::Keypair::generate(&mut ed25519_dalek_old_rand::rngs::OsRng {});
Expand Down
44 changes: 25 additions & 19 deletions benches/benches/set/mem.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::iter::successors;

use super::run_group_ref;

use criterion::{
Expand Down Expand Up @@ -55,13 +53,7 @@ pub fn run(c: &mut Criterion) {
]),
);

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 = super::generate_linear_costs();

run_group_ref(
&mut c.benchmark_group("cfei"),
Expand Down Expand Up @@ -114,16 +106,30 @@ pub fn run(c: &mut Criterion) {
}
mem_mcp.finish();

run_group_ref(
&mut c.benchmark_group("mcpi"),
"mcpi",
VmBench::new(op::mcpi(0x10, RegId::ZERO, Imm12::MAX.to_u16()))
.with_prepare_script(vec![
op::movi(0x11, Imm12::MAX.to_u16() as u32),
op::aloc(0x11),
op::move_(0x10, RegId::HP),
]),
);
let mut mem_mcpi = c.benchmark_group("mcpi");

let mut imm12_linear: Vec<_> = linear
.iter()
.copied()
.take_while(|p| *p < (1 << 12))
.collect();
imm12_linear.push((1 << 12) - 1);
for i in &imm12_linear {
let i_as_u16: u16 = (*i).try_into().unwrap();
mem_mcpi.throughput(Throughput::Bytes(*i as u64));
run_group_ref(
&mut mem_mcpi,
format!("{i}"),
VmBench::new(op::mcpi(0x10, RegId::ZERO, i_as_u16)).with_prepare_script(
vec![
op::movi(0x11, *i),
op::aloc(0x11),
op::move_(0x10, RegId::HP),
],
),
);
}
mem_mcpi.finish();

let mut mem_meq = c.benchmark_group("meq");
for i in &linear {
Expand Down
13 changes: 13 additions & 0 deletions benches/benches/set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@ pub mod flow;
pub mod mem;

pub use super::run_group_ref;

use core::iter::successors;

fn generate_linear_costs() -> 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)
.map(|f| f as u32)
.collect::<Vec<_>>();
l.sort_unstable();
linear.extend(l);
linear
}

0 comments on commit 9117a22

Please sign in to comment.