Skip to content

Commit

Permalink
perf: Add rendering benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Jun 30, 2024
1 parent 5522509 commit 92746a3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions benches/bench_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use criterion::criterion_main;
criterion_main! {
benchmarks::hierarchy::benches,
benchmarks::portgraph::benches,
benchmarks::render::benches,
benchmarks::toposort::benches,
benchmarks::convex::benches,
}
1 change: 1 addition & 0 deletions benches/benchmarks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pub mod generators;
pub mod convex;
pub mod hierarchy;
pub mod portgraph;
pub mod render;
pub mod toposort;
60 changes: 60 additions & 0 deletions benches/benchmarks/render.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! Benchmarks for the graph renderers.
use criterion::{black_box, criterion_group, AxisScale, BenchmarkId, Criterion, PlotConfiguration};
use portgraph::render::{DotFormat, MermaidFormat};

use super::generators::{make_hierarchy, make_two_track_dag, make_weights};

fn bench_render_mermaid(c: &mut Criterion) {
let mut g = c.benchmark_group("Mermaid rendering. Graph with hierarchy.");
g.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));

for size in [100, 1_000, 10_000] {
let graph = make_two_track_dag(size);
let hierarchy = make_hierarchy(&graph);
let weights = make_weights(&graph);
g.bench_with_input(BenchmarkId::new("hierarchy", size), &size, |b, _size| {
b.iter(|| {
black_box(
graph
.mermaid_format()
.with_hierarchy(&hierarchy)
.with_weights(&weights)
.finish(),
)
})
});
}
g.finish();
}

fn bench_render_dot(c: &mut Criterion) {
let mut g = c.benchmark_group("Dot rendering. Graph with tree hierarchy.");
g.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));

for size in [100, 1_000, 10_000] {
let graph = make_two_track_dag(size);
let hierarchy = make_hierarchy(&graph);
let weights = make_weights(&graph);
g.bench_with_input(BenchmarkId::new("hierarchy", size), &size, |b, _size| {
b.iter(|| {
black_box(
graph
.dot_format()
.with_hierarchy(&hierarchy)
.with_weights(&weights)
.finish(),
)
})
});
}
g.finish();
}

criterion_group! {
name = benches;
config = Criterion::default();
targets =
bench_render_mermaid,
bench_render_dot,
}

0 comments on commit 92746a3

Please sign in to comment.