Skip to content

Commit

Permalink
Fix bench
Browse files Browse the repository at this point in the history
  • Loading branch information
0HyperCube committed Sep 15, 2024
1 parent 09d5b95 commit fb1dd53
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions node-graph/graph-craft/benches/compile_demo_art.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use graph_craft::document::NodeNetwork;
#[cfg(any(feature = "criterion", feature = "iai"))]
use graph_craft::{document::NodeNetwork, graphene_compiler::Compiler, proto::ProtoNetwork};
use graph_craft::graphene_compiler::Compiler;
#[cfg(any(feature = "criterion", feature = "iai"))]
use graph_craft::proto::ProtoNetwork;

#[cfg(feature = "criterion")]
use criterion::{black_box, criterion_group, criterion_main, Criterion};

#[cfg(all(not(feature = "criterion"), feature = "iai"))]
use iai_callgrind::{black_box, library_benchmark, library_benchmark_group, main};

Expand All @@ -18,7 +20,6 @@ fn compile(network: NodeNetwork) -> ProtoNetwork {
let compiler = Compiler {};
compiler.compile_single(network).unwrap()
}

#[cfg(all(not(feature = "criterion"), feature = "iai"))]
fn load_from_name(name: &str) -> NodeNetwork {
let content = std::fs::read(&format!("../../demo-artwork/{name}.graphite")).expect("failed to read file");
Expand All @@ -27,7 +28,6 @@ fn load_from_name(name: &str) -> NodeNetwork {
black_box(compile(black_box(network)));
load_network(content)
}

#[cfg(feature = "criterion")]
fn compile_to_proto(c: &mut Criterion) {
let artworks = glob::glob("../../demo-artwork/*.graphite").expect("failed to read glob pattern");
Expand All @@ -42,17 +42,15 @@ fn compile_to_proto(c: &mut Criterion) {

#[cfg_attr(all(feature = "iai", not(feature = "criterion")), library_benchmark)]
#[cfg_attr(all(feature = "iai", not(feature="criterion")), benches::with_setup(args = ["isometric-fountain", "painted-dreams", "procedural-string-lights", "red-dress", "valley-of-spires"], setup = load_from_name))]
#[cfg(all(not(feature = "criterion"), feature = "iai"))]
pub fn iai_compile_to_proto(input: NodeNetwork) {
black_box(compile(input));
pub fn iai_compile_to_proto(_input: NodeNetwork) {
#[cfg(all(feature = "iai", not(feature = "criterion")))]
black_box(compile(_input));
}

#[cfg(feature = "criterion")]
criterion_group!(benches, compile_to_proto);

#[cfg(feature = "criterion")]
criterion_main!(benches);

#[cfg(all(not(feature = "criterion"), feature = "iai"))]
library_benchmark_group!(name = compile_group; benchmarks = iai_compile_to_proto);

Expand Down

0 comments on commit fb1dd53

Please sign in to comment.