use criterion::{criterion_group, criterion_main, Criterion};
use dotmax::BrailleGrid;
use std::hint::black_box;
fn bench_braille_grid_creation(c: &mut Criterion) {
c.bench_function("braille_grid_creation", |b| {
b.iter(|| black_box(BrailleGrid::new(80, 24).unwrap()));
});
}
fn bench_grid_clear(c: &mut Criterion) {
c.bench_function("grid_clear", |b| {
let mut grid = BrailleGrid::new(80, 24).unwrap();
b.iter(|| {
grid.clear();
black_box(&grid);
});
});
}
fn bench_unicode_conversion(c: &mut Criterion) {
c.bench_function("convert_cell_to_braille_char", |b| {
let mut grid = BrailleGrid::new(80, 24).unwrap();
for y in 0..24 {
for x in 0..80 {
grid.set_dot(x * 2, y * 4).unwrap();
}
}
b.iter(|| {
for y in 0..24 {
for x in 0..80 {
black_box(grid.cell_to_braille_char(x, y).unwrap());
}
}
});
});
}
fn bench_to_unicode_grid(c: &mut Criterion) {
c.bench_function("to_unicode_grid_80x24", |b| {
let mut grid = BrailleGrid::new(80, 24).unwrap();
for y in 0..24 {
for x in 0..80 {
grid.set_dot(x * 2, y * 4).unwrap();
}
}
b.iter(|| {
black_box(grid.to_unicode_grid());
});
});
}
criterion_group!(
benches,
bench_braille_grid_creation,
bench_grid_clear,
bench_unicode_conversion,
bench_to_unicode_grid
);
criterion_main!(benches);