Skip to content

Commit

Permalink
test: Add state root and contract id benchmarks (#1462)
Browse files Browse the repository at this point in the history
Related issues:
- FuelLabs/fuel-vm#599

---------

Co-authored-by: xgreenx <xgreenx9999@gmail.com>
  • Loading branch information
Brandon Vrooman and xgreenx committed Nov 1, 2023
1 parent 203beaa commit 0a78b32
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Description of the upcoming release here.

### Added
- [#1642](https://github.com/FuelLabs/fuel-core/pull/1462): Added benchmark to measure the performance of contract state and contract ID calculation; use for gas costing.
- [#1465](https://github.com/FuelLabs/fuel-core/pull/1465): Improvements for keygen cli and crates
- [#1457](https://github.com/FuelLabs/fuel-core/pull/1457): Fixing incorrect measurement for fast(µs) opcodes.
- [#1456](https://github.com/FuelLabs/fuel-core/pull/1456): Added flushing of the RocksDB during a graceful shutdown.
Expand Down
29 changes: 28 additions & 1 deletion benches/benches/contract_root.rs → benches/benches/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use criterion::{
Criterion,
Throughput,
};
use fuel_core_types::fuel_tx::Contract;
use fuel_core_types::fuel_tx::{
Contract,
StorageSlot,
};
use rand::{
rngs::StdRng,
Rng,
Expand Down Expand Up @@ -46,3 +49,27 @@ pub fn contract_root(c: &mut Criterion) {

group.finish();
}

pub fn state_root(c: &mut Criterion) {
let rng = &mut StdRng::seed_from_u64(8586);

let mut group = c.benchmark_group("state_root");

const N: usize = 20;
let sizes = successors(Some(2), |n| Some(n * 2)).take(N);
for (i, size) in sizes.enumerate() {
let gen_storage_slot = || rng.gen::<StorageSlot>();
let storage_slots = std::iter::repeat_with(gen_storage_slot)
.take(size)
.collect::<Vec<_>>();
group.throughput(Throughput::Bytes(size as u64));
let name = format!("state_root_from_slots_2^{exp:#02}", exp = i + 1);
group.bench_function(name, |b| {
b.iter(|| {
Contract::initial_state_root(storage_slots.iter());
})
});
}

group.finish();
}
5 changes: 3 additions & 2 deletions benches/benches/vm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod contract_root;
mod contract;
mod utils;
mod vm_set;

Expand All @@ -11,7 +11,7 @@ use criterion::{
Criterion,
};

use contract_root::*;
use contract::*;
use fuel_core_benches::*;
use fuel_core_storage::transactional::Transaction;
use fuel_core_types::fuel_asm::Instruction;
Expand Down Expand Up @@ -95,6 +95,7 @@ fn vm(c: &mut Criterion) {
flow::run(c);
mem::run(c);
contract_root(c);
state_root(c);
}

criterion_group!(benches, vm);
Expand Down

0 comments on commit 0a78b32

Please sign in to comment.