Skip to content
Snippets Groups Projects
Commit e417f986 authored by Nikolay Volf's avatar Nikolay Volf Committed by GitHub
Browse files

wasm per block size bench (#4982)

parent a98e6b0e
No related merge requests found
......@@ -28,7 +28,9 @@
//! to much configuring - just block full of randomized transactions.
//! It is not supposed to measure runtime modules weight correctness
use std::fmt;
use node_testing::bench::{BenchDb, Profile};
use node_primitives::Block;
use sp_runtime::generic::BlockId;
use criterion::{Criterion, criterion_group, criterion_main};
use sc_client_api::backend::Backend;
......@@ -38,12 +40,17 @@ criterion_group!(
config = Criterion::default().sample_size(50).warm_up_time(std::time::Duration::from_secs(20));
targets = bench_block_import
);
criterion_group!(
name = wasm_size;
config = Criterion::default().sample_size(10);
targets = bench_wasm_size_import
);
criterion_group!(
name = profile;
config = Criterion::default().sample_size(10);
targets = profile_block_import
);
criterion_main!(benches, profile);
criterion_main!(benches, profile, wasm_size);
fn bench_block_import(c: &mut Criterion) {
sc_cli::init_logger("");
......@@ -139,3 +146,41 @@ fn profile_block_import(c: &mut Criterion) {
},
);
}
struct Setup {
db: BenchDb,
block: Block,
}
impl fmt::Debug for Setup {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Setup: {} tx/block", self.block.extrinsics.len())
}
}
fn bench_wasm_size_import(c: &mut Criterion) {
sc_cli::init_logger("");
let mut setups = Vec::new();
for block_size in 5..15 {
let mut db = BenchDb::new(block_size*50);
let block = db.generate_block(block_size * 50);
setups.push(Setup { db, block });
}
c.bench_function_over_inputs("wasm_size_import",
move |bencher, setup| {
bencher.iter_batched(
|| {
setup.db.create_context(Profile::Wasm)
},
|mut context| {
context.import_block(setup.block.clone());
},
criterion::BatchSize::PerIteration,
);
},
setups,
);
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment