Skip to content

Commit 4f1cbda

Browse files
authored
Merge pull request #2049 from CosmWasm/aw/extend-analyze-benches
Extend `analyze` bench suite
2 parents a229f37 + 651a1f3 commit 4f1cbda

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

packages/vm/benches/main.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
22

33
use rand::Rng;
44
use std::sync::Arc;
5-
use std::thread;
65
use std::time::{Duration, SystemTime};
6+
use std::{fs, thread};
77
use tempfile::TempDir;
88

99
use cosmwasm_std::{coins, Checksum, Empty};
@@ -34,6 +34,17 @@ const DEFAULT_CAPABILITIES: &str = "cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,itera
3434
static HACKATOM: &[u8] = include_bytes!("../testdata/hackatom.wasm");
3535
static CYBERPUNK: &[u8] = include_bytes!("../testdata/cyberpunk.wasm");
3636

37+
static BENCH_CONTRACTS: &[&str] = &[
38+
"cyberpunk_rust170.wasm",
39+
"cyberpunk.wasm",
40+
"floaty_1.0.wasm",
41+
"floaty_1.2.wasm",
42+
"floaty_2.0.wasm",
43+
"hackatom_1.0.wasm",
44+
"hackatom_1.2.wasm",
45+
"hackatom.wasm",
46+
];
47+
3748
fn bench_instance(c: &mut Criterion) {
3849
let mut group = c.benchmark_group("Instance");
3950

@@ -169,16 +180,19 @@ fn bench_cache(c: &mut Criterion) {
169180
});
170181
});
171182

172-
group.bench_function("analyze", |b| {
183+
for contract_name in BENCH_CONTRACTS {
184+
let contract_wasm = fs::read(format!("testdata/{contract_name}")).unwrap();
173185
let cache: Cache<MockApi, MockStorage, MockQuerier> =
174186
unsafe { Cache::new(options.clone()).unwrap() };
175-
let checksum = cache.save_wasm(HACKATOM).unwrap();
187+
let checksum = cache.save_wasm(&contract_wasm).unwrap();
176188

177-
b.iter(|| {
178-
let result = cache.analyze(&checksum);
179-
assert!(result.is_ok());
189+
group.bench_function(format!("analyze_{contract_name}"), |b| {
190+
b.iter(|| {
191+
let result = cache.analyze(&checksum);
192+
assert!(result.is_ok());
193+
});
180194
});
181-
});
195+
}
182196

183197
group.bench_function("instantiate from fs", |b| {
184198
let non_memcache = CacheOptions::new(

0 commit comments

Comments
 (0)