Skip to content

Commit

Permalink
add benchmarks for uv mode lines
Browse files Browse the repository at this point in the history
  • Loading branch information
murl-digital committed Apr 21, 2024
1 parent b1f7520 commit 2283268
Showing 1 changed file with 93 additions and 1 deletion.
94 changes: 93 additions & 1 deletion crates/epaint/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,94 @@ fn thin_large_line_solid(c: &mut Criterion) {
});
}

fn thick_line_uv(c: &mut Criterion) {
c.bench_function("thick_uv_line", move |b| {
let line = [pos2(0.0, 0.0), pos2(50.0, 0.0), pos2(100.0, 1.0)];
let mut path = Path::default();
path.add_open_points(&line);

b.iter(|| {
let mut mesh = Mesh::default();
path.stroke_closed(
1.5,
&PathStroke::new_uv(2.0, |_, p| {
black_box(p * 2.0);
Color32::RED
}),
&mut mesh,
);

black_box(mesh);
});
});
}

fn thick_large_line_uv(c: &mut Criterion) {
c.bench_function("thick_large_uv_line", move |b| {
let line = (0..1000).map(|i| pos2(i as f32, 10.0)).collect::<Vec<_>>();
let mut path = Path::default();
path.add_open_points(&line);

b.iter(|| {
let mut mesh = Mesh::default();
path.stroke_closed(
1.5,
&PathStroke::new_uv(2.0, |_, p| {
black_box(p * 2.0);
Color32::RED
}),
&mut mesh,
);

black_box(mesh);
});
});
}

fn thin_line_uv(c: &mut Criterion) {
c.bench_function("thin_uv_line", move |b| {
let line = [pos2(0.0, 0.0), pos2(50.0, 0.0), pos2(100.0, 1.0)];
let mut path = Path::default();
path.add_open_points(&line);

b.iter(|| {
let mut mesh = Mesh::default();
path.stroke_closed(
1.5,
&PathStroke::new_uv(2.0, |_, p| {
black_box(p * 2.0);
Color32::RED
}),
&mut mesh,
);

black_box(mesh);
});
});
}

fn thin_large_line_uv(c: &mut Criterion) {
c.bench_function("thin_large_uv_line", move |b| {
let line = (0..1000).map(|i| pos2(i as f32, 10.0)).collect::<Vec<_>>();
let mut path = Path::default();
path.add_open_points(&line);

b.iter(|| {
let mut mesh = Mesh::default();
path.stroke_closed(
1.5,
&PathStroke::new_uv(2.0, |_, p| {
black_box(p * 2.0);
Color32::RED
}),
&mut mesh,
);

black_box(mesh);
});
});
}

criterion_group!(
benches,
single_dashed_lines,
Expand All @@ -140,6 +228,10 @@ criterion_group!(
thick_line_solid,
thick_large_line_solid,
thin_line_solid,
thin_large_line_solid
thin_large_line_solid,
thick_line_uv,
thick_large_line_uv,
thin_line_uv,
thin_large_line_uv
);
criterion_main!(benches);

0 comments on commit 2283268

Please sign in to comment.