Introduce layered_text benchmarks

This commit is contained in:
Héctor Ramón Jiménez 2024-05-01 15:39:05 +02:00
parent a11784f9ed
commit e2aee80aa1
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -3,7 +3,7 @@ use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use iced::alignment; use iced::alignment;
use iced::mouse; use iced::mouse;
use iced::widget::{canvas, text}; use iced::widget::{canvas, stack, text};
use iced::{ use iced::{
Color, Element, Font, Length, Pixels, Point, Rectangle, Size, Theme, Color, Element, Font, Length, Pixels, Point, Rectangle, Size, Theme,
}; };
@ -16,6 +16,13 @@ criterion_group!(benches, wgpu_benchmark);
pub fn wgpu_benchmark(c: &mut Criterion) { pub fn wgpu_benchmark(c: &mut Criterion) {
c.bench_function("wgpu — canvas (light)", |b| benchmark(b, scene(10))); c.bench_function("wgpu — canvas (light)", |b| benchmark(b, scene(10)));
c.bench_function("wgpu — canvas (heavy)", |b| benchmark(b, scene(1_000))); c.bench_function("wgpu — canvas (heavy)", |b| benchmark(b, scene(1_000)));
c.bench_function("wgpu - layered text (light)", |b| {
benchmark(b, layered_text(10));
});
c.bench_function("wgpu - layered text (heavy)", |b| {
benchmark(b, layered_text(1_000));
});
} }
fn benchmark( fn benchmark(
@ -125,15 +132,7 @@ fn benchmark(
}); });
} }
fn scene<'a, Message: 'a, Theme: 'a>( fn scene<'a, Message: 'a>(n: usize) -> Element<'a, Message, Theme, Renderer> {
n: usize,
) -> Element<'a, Message, Theme, Renderer> {
canvas(Scene { n })
.width(Length::Fill)
.height(Length::Fill)
.into()
}
struct Scene { struct Scene {
n: usize, n: usize,
} }
@ -174,3 +173,18 @@ impl<Message, Theme> canvas::Program<Message, Theme, Renderer> for Scene {
})] })]
} }
} }
canvas(Scene { n })
.width(Length::Fill)
.height(Length::Fill)
.into()
}
fn layered_text<'a, Message: 'a>(
n: usize,
) -> Element<'a, Message, Theme, Renderer> {
stack((0..n).map(|i| text(format!("I am paragraph {i}!")).into()))
.width(Length::Fill)
.height(Length::Fill)
.into()
}