#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(
feature = "text-shaping",
feature = "fonts-vector-latin",
feature = "fonts-complex",
feature = "fonts-cjk"
))]
use criterion::{criterion_group, criterion_main, Criterion};
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(
feature = "text-shaping",
feature = "fonts-vector-latin",
feature = "fonts-complex",
feature = "fonts-cjk"
))]
use rust_widgets::render::text;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(
feature = "text-shaping",
feature = "fonts-vector-latin",
feature = "fonts-complex",
feature = "fonts-cjk"
))]
use rust_widgets::render::text::{Cell, InkKind};
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(
feature = "text-shaping",
feature = "fonts-vector-latin",
feature = "fonts-complex",
feature = "fonts-cjk"
))]
fn bench_repeat_lookup(c: &mut Criterion) {
let mut group = c.benchmark_group("face_for_char/repeat");
group.bench_function("cached", |b| b.iter(|| text::face_for_char('A')));
group.bench_function("uncached", |b| b.iter(|| text::face_for_char_uncached('A')));
group.finish();
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(
feature = "text-shaping",
feature = "fonts-vector-latin",
feature = "fonts-complex",
feature = "fonts-cjk"
))]
fn bench_caption_lookup(c: &mut Criterion) {
let caption: Vec<char> = if text::face_for_char('\u{4E2D}').is_some() {
vec!['H', 'e', 'l', 'l', 'o', ' ', '\u{4E2D}', '\u{6587}']
} else {
vec!['H', 'e', 'l', 'l', 'o', ' ', 'W', 'd']
};
let mut group = c.benchmark_group("face_for_char/caption");
group.bench_function("cached", |b| {
b.iter(|| {
for &ch in &caption {
std::hint::black_box(text::face_for_char(ch));
}
})
});
group.bench_function("uncached", |b| {
b.iter(|| {
for &ch in &caption {
std::hint::black_box(text::face_for_char_uncached(ch));
}
})
});
group.finish();
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(
feature = "text-shaping",
feature = "fonts-vector-latin",
feature = "fonts-complex",
feature = "fonts-cjk"
))]
fn bench_paint_active(c: &mut Criterion) {
let cell = Cell::new(16, 16);
let mut buffer = vec![0u8; cell.area() * 4];
let mut group = c.benchmark_group("paint_active 16x16");
group.bench_function("latin 'A'", |b| {
b.iter(|| {
let painted = text::paint_active('A', cell, &mut buffer);
debug_assert!(painted.is_some(), "a Latin glyph must paint on a vector-face build");
})
});
if text::face_for_char('\u{4E2D}').is_some() {
group.bench_function("cjk '\u{4E2D}'", |b| {
b.iter(|| {
let painted = text::paint_active('\u{4E2D}', cell, &mut buffer);
debug_assert!(painted.is_some(), "a covered ideograph must paint");
if let Some(painted) = painted {
debug_assert_eq!(painted.ink, InkKind::Coverage);
}
})
});
}
group.finish();
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(
feature = "text-shaping",
feature = "fonts-vector-latin",
feature = "fonts-complex",
feature = "fonts-cjk"
))]
criterion_group!(font_benches, bench_repeat_lookup, bench_caption_lookup, bench_paint_active);
#[cfg(target_arch = "wasm32")]
fn main() {}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(
feature = "text-shaping",
feature = "fonts-vector-latin",
feature = "fonts-complex",
feature = "fonts-cjk"
))]
criterion_main!(font_benches);
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(any(
feature = "text-shaping",
feature = "fonts-vector-latin",
feature = "fonts-complex",
feature = "fonts-cjk"
)))]
fn main() {}