Debian Codegraph @

crates/wasm-smith/benches/corpus.rs

raw
1 use arbitrary::{Arbitrary, Unstructured};
2 use criterion::{Criterion, criterion_group, criterion_main};
3 use std::hint::black_box;
4 use wasm_smith::Module;
5
6 pub fn benchmark_corpus(c: &mut Criterion) {
7 let mut corpus = Vec::with_capacity(2000);
8 let entries = std::fs::read_dir("./benches/corpus").expect("failed to read dir");
9 for e in entries {
10 let e = e.expect("failed to read dir entry");
11 let seed = std::fs::read(e.path()).expect("failed to read seed file");
12 corpus.push(seed);
13 }
14
15 // Benchmark how long it takes to generate a module for every seed in our
16 // corpus (taken from the `validate` fuzz target).
17 c.bench_function("corpus", |b| {
18 b.iter(|| {
19 for seed in &corpus {
20 let seed = black_box(seed);
21 let mut u = Unstructured::new(seed);
22 let result = Module::arbitrary(&mut u);
23 let _ = black_box(result);
24 }
25 })
26 });
27 }
28
29 criterion_group!(benches, benchmark_corpus);
30 criterion_main!(benches);