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.
45 lines
1.4 KiB
Rust
45 lines
1.4 KiB
Rust
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
use tele_tui::message_grouping::group_messages;
|
|
use tele_tui::tdlib::types::MessageBuilder;
|
|
use tele_tui::types::MessageId;
|
|
|
|
fn create_test_messages(count: usize) -> Vec<tele_tui::tdlib::MessageInfo> {
|
|
(0..count)
|
|
.map(|i| {
|
|
let builder = MessageBuilder::new(MessageId::new(i as i64))
|
|
.sender_name(&format!("User{}", i % 10))
|
|
.text(&format!("Test message number {} with some longer text to make it more realistic", i))
|
|
.date(1640000000 + (i as i32 * 60));
|
|
|
|
if i % 2 == 0 {
|
|
builder.outgoing().read().build()
|
|
} else {
|
|
builder.incoming().build()
|
|
}
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
fn benchmark_group_100_messages(c: &mut Criterion) {
|
|
let messages = create_test_messages(100);
|
|
|
|
c.bench_function("group_100_messages", |b| {
|
|
b.iter(|| {
|
|
group_messages(black_box(&messages))
|
|
});
|
|
});
|
|
}
|
|
|
|
fn benchmark_group_500_messages(c: &mut Criterion) {
|
|
let messages = create_test_messages(500);
|
|
|
|
c.bench_function("group_500_messages", |b| {
|
|
b.iter(|| {
|
|
group_messages(black_box(&messages))
|
|
});
|
|
});
|
|
}
|
|
|
|
criterion_group!(benches, benchmark_group_100_messages, benchmark_group_500_messages);
|
|
criterion_main!(benches);
|