diff options
author | 2024-05-08 20:29:27 +0200 | |
---|---|---|
committer | 2024-05-08 20:29:27 +0200 | |
commit | fb5f1ba0bc728069b63d299e98411fad483b4177 (patch) | |
tree | 70dc77c0b2e147d88eac7d075f81e2af3d8c141b /benches | |
parent | f1beb56a9af57c708ab51c44e713fdafa0a496ea (diff) | |
download | iced-fb5f1ba0bc728069b63d299e98411fad483b4177.tar.gz iced-fb5f1ba0bc728069b63d299e98411fad483b4177.tar.bz2 iced-fb5f1ba0bc728069b63d299e98411fad483b4177.zip |
Create dynamic text `wgpu` benchmark
Diffstat (limited to 'benches')
-rw-r--r-- | benches/ipsum.txt | 9 | ||||
-rw-r--r-- | benches/wgpu.rs | 63 |
2 files changed, 59 insertions, 13 deletions
diff --git a/benches/ipsum.txt b/benches/ipsum.txt new file mode 100644 index 00000000..3e2d6396 --- /dev/null +++ b/benches/ipsum.txt @@ -0,0 +1,9 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at elit mollis, dictum nunc non, tempus metus. Sed iaculis ac mauris eu lobortis. Integer elementum venenatis eros, id placerat odio feugiat vel. Maecenas consequat convallis tincidunt. Nunc eu lorem justo. Praesent quis ornare sapien. Aliquam interdum tortor ut rhoncus faucibus. Suspendisse molestie scelerisque nulla, eget sodales lacus sodales vel. Nunc placerat id arcu sodales venenatis. Praesent ullamcorper viverra nibh eget efficitur. Aliquam molestie felis vehicula, finibus sapien eget, accumsan purus. Praesent vestibulum eleifend consectetur. Sed tincidunt lectus a libero efficitur, non scelerisque lectus tincidunt. + +Cras ullamcorper tincidunt tellus non tempor. Integer pulvinar turpis quam, nec pharetra purus egestas non. Vivamus sed ipsum consequat, dignissim ante et, suscipit nibh. Quisque et mauris eu erat rutrum cursus. Pellentesque ut neque eu neque eleifend auctor ac hendrerit dolor. Morbi eget egestas ex. Integer hendrerit ipsum in enim bibendum, at vehicula ipsum dapibus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce tempus consectetur tortor, vel fermentum sem pulvinar eget. Maecenas rutrum fringilla eros a pellentesque. Cras quis magna consectetur, tristique massa vel, aliquet nunc. Aliquam erat volutpat. Suspendisse porttitor risus id auctor fermentum. Vivamus efficitur tellus sed tortor cursus tincidunt. Sed auctor varius arcu, non congue tellus vehicula finibus. + +Fusce a tincidunt urna. Nunc at quam ac enim tempor vehicula imperdiet in sapien. Donec lobortis tristique felis vel semper. Quisque vulputate felis eu enim vestibulum malesuada. Fusce a lobortis mauris, iaculis eleifend ligula. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vivamus sodales vel elit dignissim mattis. + +Aliquam placerat vulputate dignissim. Proin pellentesque vitae arcu ut feugiat. Nunc mi felis, ornare at gravida sed, vestibulum sed urna. Duis fermentum maximus viverra. Donec imperdiet pellentesque sollicitudin. Cras non sem quis metus bibendum molestie. Duis imperdiet nec lectus eu rutrum. Mauris congue enim purus, in iaculis arcu dapibus ut. Nullam id erat tincidunt, iaculis dolor non, lobortis magna. Proin convallis scelerisque maximus. Morbi at lorem fringilla libero blandit fringilla. Ut aliquet tellus non sem dictum viverra. Aenean venenatis purus eget lacus placerat, non mollis mauris pellentesque. + +Etiam elit diam, aliquet quis suscipit non, condimentum viverra odio. Praesent mi enim, suscipit id mi in, rhoncus ultricies lorem. Nulla facilisi. Integer convallis sagittis euismod. Vestibulum porttitor sodales turpis ac accumsan. Nullam molestie turpis vel lacus tincidunt, sed finibus erat pharetra. Nullam vestibulum turpis id sollicitudin accumsan. Praesent eget posuere lacus. Donec vehicula, nisl nec suscipit porta, felis lorem gravida orci, a hendrerit tellus nibh sit amet elit. diff --git a/benches/wgpu.rs b/benches/wgpu.rs index 2d308666..02c7b1f9 100644 --- a/benches/wgpu.rs +++ b/benches/wgpu.rs @@ -3,7 +3,7 @@ use criterion::{criterion_group, criterion_main, Bencher, Criterion}; use iced::alignment; use iced::mouse; -use iced::widget::{canvas, stack, text}; +use iced::widget::{canvas, scrollable, stack, text}; use iced::{ Color, Element, Font, Length, Pixels, Point, Rectangle, Size, Theme, }; @@ -14,20 +14,31 @@ criterion_group!(benches, wgpu_benchmark); #[allow(unused_results)] pub fn wgpu_benchmark(c: &mut Criterion) { - 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 (light)", |b| { + benchmark(b, |_| scene(10)) + }); + 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)); + benchmark(b, |_| layered_text(10)); }); c.bench_function("wgpu - layered text (heavy)", |b| { - benchmark(b, layered_text(1_000)); + benchmark(b, |_| layered_text(1_000)); + }); + + c.bench_function("wgpu - dynamic text (light)", |b| { + benchmark(b, |i| dynamic_text(1_000, i)); + }); + c.bench_function("wgpu - dynamic text (heavy)", |b| { + benchmark(b, |i| dynamic_text(100_000, i)); }); } -fn benchmark( +fn benchmark<'a>( bencher: &mut Bencher<'_>, - widget: Element<'_, (), Theme, Renderer>, + view: impl Fn(usize) -> Element<'a, (), Theme, Renderer>, ) { use iced_futures::futures::executor; use iced_wgpu::graphics; @@ -94,14 +105,17 @@ fn benchmark( let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); - let mut user_interface = runtime::UserInterface::build( - widget, - viewport.logical_size(), - runtime::user_interface::Cache::default(), - &mut renderer, - ); + let mut i = 0; + let mut cache = Some(runtime::user_interface::Cache::default()); bencher.iter(|| { + let mut user_interface = runtime::UserInterface::build( + view(i), + viewport.logical_size(), + cache.take().unwrap(), + &mut renderer, + ); + let _ = user_interface.draw( &mut renderer, &Theme::Dark, @@ -111,6 +125,8 @@ fn benchmark( mouse::Cursor::Unavailable, ); + cache = Some(user_interface.into_cache()); + let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None, @@ -130,6 +146,8 @@ fn benchmark( let submission = engine.submit(&queue, encoder); let _ = device.poll(wgpu::Maintain::WaitForSubmissionIndex(submission)); + + i += 1; }); } @@ -189,3 +207,22 @@ fn layered_text<'a, Message: 'a>( .height(Length::Fill) .into() } + +fn dynamic_text<'a, Message: 'a>( + n: usize, + i: usize, +) -> Element<'a, Message, Theme, Renderer> { + const LOREM_IPSUM: &'static str = include_str!("ipsum.txt"); + + scrollable( + text(format!( + "{}... Iteration {i}", + std::iter::repeat(LOREM_IPSUM.chars()) + .flatten() + .take(n) + .collect::<String>(), + )) + .size(10), + ) + .into() +} |