Skip to content

Commit

Permalink
Fix benchmark runner
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueDoctor committed Aug 14, 2024
1 parent 8e46177 commit c469ead
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions node-graph/graph-craft/benches/compile_demo_art.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ fn compile(network: NodeNetwork) -> ProtoNetwork {
compiler.compile_single(network).unwrap()
}

fn bench_compile(path: PathBuf) {
let content = std::fs::read(&path).expect("failed to read file");
let network = load_network(std::str::from_utf8(&content).unwrap());
black_box(compile(black_box(network)));
fn load_from_name(name: &str) -> NodeNetwork {
let content = std::fs::read(&format!("../../demo-artwork/{name}.graphite")).expect("failed to read file");
let content = std::str::from_utf8(&content).unwrap();
load_network(content)
}

#[cfg(feature = "criterion")]
Expand All @@ -29,17 +29,16 @@ fn compile_to_proto(c: &mut Criterion) {
for path in artworks {
let Ok(path) = path else { continue };
let name = path.file_stem().unwrap().to_str().unwrap();
c.bench_function(name, |b| b.iter(|| bench_compile(path.clone())));
let content = std::fs::read(&path).expect("failed to read file");
let network = load_network(std::str::from_utf8(&content).unwrap());
c.bench_function(name, |b| b.iter_batched(|| network.clone(), |network| compile(black_box(network)), criterion::BatchSize::SmallInput));
}
}

#[cfg_attr(feature = "iai", library_benchmark)]
fn iai_compile_to_proto() {
let artworks = glob::glob("../../demo-artwork/*.graphite").expect("failed to read glob pattern");
for path in artworks {
let Ok(path) = path else { continue };
bench_compile(path);
}
#[cfg_attr(feature = "iai", benches::with_setup(args = ["isometric-fountain", "painted-dreams", "procedural-string-lights", "red-dress", "valley-of-spires"], setup = load_from_name))]
fn iai_compile_to_proto(input: NodeNetwork) {
black_box(compile(input));
}

#[cfg(feature = "criterion")]
Expand Down

0 comments on commit c469ead

Please sign in to comment.