From f25a3acc98564ceefc2307a65c49c6eac329d34e Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 18 Oct 2024 10:23:53 -0700 Subject: [PATCH] test: benchmark compilation --- Cargo.lock | 1 + testing/integration/Cargo.toml | 5 +++ testing/integration/benches/compile.rs | 46 ++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 testing/integration/benches/compile.rs diff --git a/Cargo.lock b/Cargo.lock index 64ce97836..68b6d79de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2557,6 +2557,7 @@ dependencies = [ "blake2b_simd", "bls-signatures", "cid 0.10.1", + "criterion", "fil_builtin_actors_bundle", "futures", "fvm", diff --git a/testing/integration/Cargo.toml b/testing/integration/Cargo.toml index 234139ee2..db56e9238 100644 --- a/testing/integration/Cargo.toml +++ b/testing/integration/Cargo.toml @@ -40,8 +40,13 @@ bls-signatures = { workspace = true } hex = { workspace = true } minstant = { workspace = true } wat = "1.0.66" +criterion = { workspace = true } [features] default = [] m2-native = [] calibration = ["fvm/gas_calibration"] + +[[bench]] +name = "compile" +harness = false diff --git a/testing/integration/benches/compile.rs b/testing/integration/benches/compile.rs new file mode 100644 index 000000000..e80126fb3 --- /dev/null +++ b/testing/integration/benches/compile.rs @@ -0,0 +1,46 @@ +// Copyright 2021-2023 Protocol Labs +// SPDX-License-Identifier: Apache-2.0, MIT +use std::hint::black_box; +use std::time::Duration; + +use cid::Cid; +use criterion::{criterion_group, criterion_main, Criterion}; +use fvm::engine::EnginePool; +use fvm::machine::{Manifest, NetworkConfig}; + +use fvm_integration_tests::bundle; +use fvm_ipld_blockstore::MemoryBlockstore; +use fvm_ipld_encoding::CborStore; +use fvm_shared::version::NetworkVersion; + +fn bench_compile(c: &mut Criterion) { + c.bench_function("bench actor compile", |b| { + let blockstore = MemoryBlockstore::default(); + let bundle_cid = bundle::import_bundle(&blockstore, actors_v12::BUNDLE_CAR).unwrap(); + + let (manifest_version, manifest_cid): (u32, Cid) = + blockstore.get_cbor(&bundle_cid).unwrap().unwrap(); + let manifest = Manifest::load(&blockstore, &manifest_cid, manifest_version).unwrap(); + let nc = NetworkConfig::new(NetworkVersion::V21); + b.iter_batched( + || EnginePool::new((&nc).into()).unwrap(), + |engine| { + black_box( + engine + .acquire() + .preload_all(&blockstore, manifest.builtin_actor_codes()) + .unwrap(), + ); + }, + criterion::BatchSize::SmallInput, + ) + }); +} + +criterion_group! { + name = benches; + config = Criterion::default().sample_size(10).measurement_time(Duration::from_secs(30)); + targets = bench_compile +} + +criterion_main!(benches);