egui/egui_demo_lib/benches/benchmark.rs

104 lines
3.3 KiB
Rust
Raw Normal View History

2020-05-20 19:20:39 +00:00
use criterion::{criterion_group, criterion_main, Criterion};
use egui_demo_lib::LOREM_IPSUM_LONG;
2020-05-20 19:20:39 +00:00
pub fn criterion_benchmark(c: &mut Criterion) {
let raw_input = egui::RawInput::default();
2020-05-20 19:20:39 +00:00
2020-09-09 10:41:59 +00:00
{
let mut ctx = egui::CtxRef::default();
let mut demo_windows = egui_demo_lib::DemoWindows::default();
2020-09-09 10:41:59 +00:00
2021-03-29 20:48:13 +00:00
// The most end-to-end benchmark.
c.bench_function("demo_windows_minimal with tesselation (realistic)", |b| {
b.iter(|| {
ctx.begin_frame(raw_input.clone());
demo_windows.ui(&ctx);
let (_, shapes) = ctx.end_frame();
ctx.tessellate(shapes)
})
});
c.bench_function("demo_windows_minimal (no tesselation)", |b| {
b.iter(|| {
ctx.begin_frame(raw_input.clone());
demo_windows.ui(&ctx);
ctx.end_frame()
})
});
}
{
let mut ctx = egui::CtxRef::default();
ctx.memory().set_everything_is_visible(true); // give us everything
let mut demo_windows = egui_demo_lib::DemoWindows::default();
c.bench_function("demo_windows_full", |b| {
2020-09-09 10:41:59 +00:00
b.iter(|| {
ctx.begin_frame(raw_input.clone());
demo_windows.ui(&ctx);
2020-09-09 10:41:59 +00:00
ctx.end_frame()
})
});
}
{
let mut ctx = egui::CtxRef::default();
ctx.memory().set_everything_is_visible(true); // give us everything
let mut demo_windows = egui_demo_lib::DemoWindows::default();
ctx.begin_frame(raw_input.clone());
demo_windows.ui(&ctx);
2021-01-10 10:43:01 +00:00
let (_, shapes) = ctx.end_frame();
2021-01-10 10:43:01 +00:00
c.bench_function("tessellate", |b| b.iter(|| ctx.tessellate(shapes.clone())));
}
2020-09-09 10:41:59 +00:00
{
let mut ctx = egui::CtxRef::default();
ctx.begin_frame(raw_input);
egui::CentralPanel::default().show(&ctx, |ui| {
c.bench_function("label", |b| {
b.iter(|| {
ui.label(LOREM_IPSUM_LONG);
})
});
2020-09-09 10:41:59 +00:00
});
let _ = ctx.end_frame();
2020-09-09 10:41:59 +00:00
}
{
let pixels_per_point = 1.0;
let wrap_width = 512.0;
let text_style = egui::TextStyle::Body;
let fonts = egui::epaint::text::Fonts::from_definitions(
pixels_per_point,
egui::FontDefinitions::default(),
);
let font = &fonts[text_style];
c.bench_function("text layout", |b| {
b.iter(|| font.layout_multiline(LOREM_IPSUM_LONG.to_owned(), wrap_width))
});
let galley = font.layout_multiline(LOREM_IPSUM_LONG.to_owned(), wrap_width);
2021-03-28 20:44:03 +00:00
let mut tessellator = egui::epaint::Tessellator::from_options(Default::default());
let mut mesh = egui::epaint::Mesh::default();
2021-03-28 20:44:03 +00:00
c.bench_function("tessellate text", |b| {
b.iter(|| {
let fake_italics = false;
2021-03-28 20:44:03 +00:00
tessellator.tessellate_text(
&fonts,
egui::Pos2::ZERO,
&galley,
egui::Color32::WHITE,
fake_italics,
&mut mesh,
);
mesh.clear();
})
});
}
2020-05-20 19:20:39 +00:00
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);