|
| 1 | +use std::fmt::Write as _; |
| 2 | + |
1 | 3 | use criterion::{criterion_group, criterion_main, Criterion};
|
2 | 4 |
|
3 | 5 | use egui::epaint::TextShape;
|
4 | 6 | use egui_demo_lib::LOREM_IPSUM_LONG;
|
| 7 | +use rand::Rng as _; |
5 | 8 |
|
6 | 9 | pub fn criterion_benchmark(c: &mut Criterion) {
|
7 | 10 | use egui::RawInput;
|
@@ -122,6 +125,35 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
122 | 125 | });
|
123 | 126 | });
|
124 | 127 |
|
| 128 | + c.bench_function("text_layout_cached_with_modify", |b| { |
| 129 | + const MAX_REMOVED_BYTES: usize = 5000; |
| 130 | + |
| 131 | + let mut string = String::new(); |
| 132 | + // 2000 lines * 200 bytes * ~3 characters = 1.2MB |
| 133 | + string.reserve(2000 * 200 * 3 + 2000); |
| 134 | + for _ in 0..2000 { |
| 135 | + for i in 0..200u8 { |
| 136 | + write!(string, "{i:02X} ").unwrap(); |
| 137 | + } |
| 138 | + string.push('\n'); |
| 139 | + } |
| 140 | + |
| 141 | + let mut rng = rand::thread_rng(); |
| 142 | + let mut temp_string = String::with_capacity(string.len()); |
| 143 | + b.iter(|| { |
| 144 | + fonts.begin_pass(pixels_per_point, max_texture_side); |
| 145 | + temp_string.clear(); |
| 146 | + let modified_start = rng.gen_range(0..string.len()); |
| 147 | + let max_end = (modified_start + MAX_REMOVED_BYTES).min(string.len()); |
| 148 | + let modified_end = rng.gen_range(modified_start..max_end); |
| 149 | + |
| 150 | + temp_string.push_str(&string[..modified_start]); |
| 151 | + temp_string.push_str(&string[modified_end..]); |
| 152 | + |
| 153 | + fonts.layout(temp_string.clone(), font_id.clone(), text_color, wrap_width); |
| 154 | + }); |
| 155 | + }); |
| 156 | + |
125 | 157 | let galley = fonts.layout(LOREM_IPSUM_LONG.to_owned(), font_id, text_color, wrap_width);
|
126 | 158 | let font_image_size = fonts.font_image_size();
|
127 | 159 | let prepared_discs = fonts.texture_atlas().lock().prepared_discs();
|
|
0 commit comments