2020-05-20 19:20:39 +00:00
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
|
|
|
|
2021-02-08 21:53:31 +00:00
|
|
|
use egui_demo_lib::LOREM_IPSUM_LONG;
|
|
|
|
|
2020-05-20 19:20:39 +00:00
|
|
|
pub fn criterion_benchmark(c: &mut Criterion) {
|
2020-12-16 20:48:02 +00:00
|
|
|
let raw_input = egui::RawInput::default();
|
2020-05-20 19:20:39 +00:00
|
|
|
|
2020-09-09 10:41:59 +00:00
|
|
|
{
|
2020-12-19 13:48:04 +00:00
|
|
|
let mut ctx = egui::CtxRef::default();
|
2020-12-29 12:40:11 +00:00
|
|
|
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.
|
2021-04-01 19:42:45 +00:00
|
|
|
c.bench_function("demo_with_tesselate__realistic", |b| {
|
2021-03-29 20:48:13 +00:00
|
|
|
b.iter(|| {
|
|
|
|
ctx.begin_frame(raw_input.clone());
|
|
|
|
demo_windows.ui(&ctx);
|
|
|
|
let (_, shapes) = ctx.end_frame();
|
|
|
|
ctx.tessellate(shapes)
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2021-04-01 19:42:45 +00:00
|
|
|
c.bench_function("demo_no_tesselate", |b| {
|
2020-10-10 04:57:56 +00:00
|
|
|
b.iter(|| {
|
2020-10-24 08:56:23 +00:00
|
|
|
ctx.begin_frame(raw_input.clone());
|
2021-01-02 00:01:01 +00:00
|
|
|
demo_windows.ui(&ctx);
|
2020-10-10 04:57:56 +00:00
|
|
|
ctx.end_frame()
|
|
|
|
})
|
|
|
|
});
|
2021-04-01 19:42:45 +00:00
|
|
|
|
|
|
|
ctx.begin_frame(raw_input.clone());
|
|
|
|
demo_windows.ui(&ctx);
|
|
|
|
let (_, shapes) = ctx.end_frame();
|
|
|
|
c.bench_function("demo_only_tessellate", |b| {
|
|
|
|
b.iter(|| ctx.tessellate(shapes.clone()))
|
|
|
|
});
|
2020-10-10 04:57:56 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 19:42:45 +00:00
|
|
|
if false {
|
2020-12-19 13:48:04 +00:00
|
|
|
let mut ctx = egui::CtxRef::default();
|
2021-01-02 13:42:43 +00:00
|
|
|
ctx.memory().set_everything_is_visible(true); // give us everything
|
2020-12-29 12:40:11 +00:00
|
|
|
let mut demo_windows = egui_demo_lib::DemoWindows::default();
|
2021-04-01 19:42:45 +00:00
|
|
|
c.bench_function("demo_full_no_tesselate", |b| {
|
2020-09-09 10:41:59 +00:00
|
|
|
b.iter(|| {
|
2020-10-24 08:56:23 +00:00
|
|
|
ctx.begin_frame(raw_input.clone());
|
2021-01-02 00:01:01 +00:00
|
|
|
demo_windows.ui(&ctx);
|
2020-09-09 10:41:59 +00:00
|
|
|
ctx.end_frame()
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-18 08:24:31 +00:00
|
|
|
{
|
|
|
|
let mut ctx = egui::CtxRef::default();
|
|
|
|
ctx.begin_frame(raw_input.clone());
|
|
|
|
let mut ui = egui::Ui::__test();
|
|
|
|
c.bench_function("label &str", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
ui.label("the quick brown fox jumps over the lazy dog");
|
|
|
|
})
|
|
|
|
});
|
|
|
|
c.bench_function("label format!", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
ui.label(format!("the quick brown fox jumps over the lazy dog"));
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-08 21:53:31 +00:00
|
|
|
{
|
|
|
|
let pixels_per_point = 1.0;
|
|
|
|
let wrap_width = 512.0;
|
|
|
|
let text_style = egui::TextStyle::Body;
|
2021-02-14 09:53:39 +00:00
|
|
|
let fonts = egui::epaint::text::Fonts::from_definitions(
|
2021-02-08 21:53:31 +00:00
|
|
|
pixels_per_point,
|
|
|
|
egui::FontDefinitions::default(),
|
|
|
|
);
|
|
|
|
let font = &fonts[text_style];
|
2021-04-01 19:42:45 +00:00
|
|
|
c.bench_function("text_layout_uncached", |b| {
|
2021-02-08 21:53:31 +00:00
|
|
|
b.iter(|| font.layout_multiline(LOREM_IPSUM_LONG.to_owned(), wrap_width))
|
|
|
|
});
|
2021-04-01 19:42:45 +00:00
|
|
|
c.bench_function("text_layout_cached", |b| {
|
2021-03-29 20:30:18 +00:00
|
|
|
b.iter(|| fonts.layout_multiline(text_style, LOREM_IPSUM_LONG.to_owned(), wrap_width))
|
|
|
|
});
|
2021-02-08 21:53:31 +00:00
|
|
|
|
|
|
|
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());
|
2021-02-14 09:53:39 +00:00
|
|
|
let mut mesh = egui::epaint::Mesh::default();
|
2021-04-01 19:42:45 +00:00
|
|
|
c.bench_function("tessellate_text", |b| {
|
2021-02-08 21:53:31 +00:00
|
|
|
b.iter(|| {
|
|
|
|
let fake_italics = false;
|
2021-03-28 20:44:03 +00:00
|
|
|
tessellator.tessellate_text(
|
2021-03-30 19:41:39 +00:00
|
|
|
fonts.texture().size(),
|
2021-02-08 21:53:31 +00:00
|
|
|
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);
|