Files
telegram-tui/benches/formatting.rs
Mikhail Kilin e690acfb09 test: complete Phase 4 testing - utils tests and performance benchmarks
Added 9 new unit tests for utils/formatting.rs functions:
- format_date: 4 tests (today, yesterday, old, epoch)
- format_was_online: 5 tests (just now, minutes/hours/days ago, very old)

Created 3 performance benchmark files using criterion:
- benches/group_messages.rs - message grouping benchmarks
- benches/formatting.rs - timestamp/date formatting benchmarks
- benches/format_markdown.rs - markdown parsing benchmarks

Updated documentation:
- CONTEXT.md: added Phase 4.1 (Utils) and 4.2 (Benchmarks) completion
- Total coverage: 188 tests + 8 benchmarks = 196 tests (100%)

All 565 tests passing with 100% success rate.
2026-02-01 23:04:43 +03:00

44 lines
1.2 KiB
Rust

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use tele_tui::utils::formatting::{format_timestamp_with_tz, format_date, get_day};
fn benchmark_format_timestamp(c: &mut Criterion) {
c.bench_function("format_timestamp_50_times", |b| {
b.iter(|| {
for i in 0..50 {
let timestamp = 1640000000 + (i * 60);
black_box(format_timestamp_with_tz(timestamp, "+03:00"));
}
});
});
}
fn benchmark_format_date(c: &mut Criterion) {
c.bench_function("format_date_50_times", |b| {
b.iter(|| {
for i in 0..50 {
let timestamp = 1640000000 + (i * 86400);
black_box(format_date(timestamp));
}
});
});
}
fn benchmark_get_day(c: &mut Criterion) {
c.bench_function("get_day_1000_times", |b| {
b.iter(|| {
for i in 0..1000 {
let timestamp = 1640000000 + (i * 60);
black_box(get_day(timestamp));
}
});
});
}
criterion_group!(
benches,
benchmark_format_timestamp,
benchmark_format_date,
benchmark_get_day
);
criterion_main!(benches);