Split core and TUI crates

This commit is contained in:
Mikhail Kilin
2026-05-20 00:31:18 +03:00
parent 91a8700b8e
commit eefac431e5
238 changed files with 624 additions and 191 deletions

View File

@@ -0,0 +1,88 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use ratatui::style::Color;
use tdlib_rs::enums::TextEntityType;
use tdlib_rs::types::TextEntity;
use tele_tui::formatting::format_text_with_entities;
fn create_text_with_entities() -> (String, Vec<TextEntity>) {
let text = "This is bold and italic text with code and a link and mention".to_string();
let entities = vec![
TextEntity {
offset: 8,
length: 4, // bold
r#type: TextEntityType::Bold,
},
TextEntity {
offset: 17,
length: 6, // italic
r#type: TextEntityType::Italic,
},
TextEntity {
offset: 34,
length: 4, // code
r#type: TextEntityType::Code,
},
TextEntity {
offset: 45,
length: 4, // link
r#type: TextEntityType::Url,
},
TextEntity {
offset: 54,
length: 7, // mention
r#type: TextEntityType::Mention,
},
];
(text, entities)
}
fn benchmark_format_simple_text(c: &mut Criterion) {
let text = "Simple text without any formatting".to_string();
let entities = vec![];
c.bench_function("format_simple_text", |b| {
b.iter(|| format_text_with_entities(black_box(&text), black_box(&entities), Color::White));
});
}
fn benchmark_format_markdown_text(c: &mut Criterion) {
let (text, entities) = create_text_with_entities();
c.bench_function("format_markdown_text", |b| {
b.iter(|| format_text_with_entities(black_box(&text), black_box(&entities), Color::White));
});
}
fn benchmark_format_long_text(c: &mut Criterion) {
let mut text = String::new();
let mut entities = vec![];
// Создаем длинный текст с множеством форматирований
for i in 0..100 {
let start = text.len();
text.push_str(&format!("Word{} ", i));
// Добавляем форматирование к каждому 3-му слову
if i % 3 == 0 {
entities.push(TextEntity {
offset: start as i32,
length: format!("Word{}", i).len() as i32,
r#type: TextEntityType::Bold,
});
}
}
c.bench_function("format_long_text_with_100_entities", |b| {
b.iter(|| format_text_with_entities(black_box(&text), black_box(&entities), Color::White));
});
}
criterion_group!(
benches,
benchmark_format_simple_text,
benchmark_format_markdown_text,
benchmark_format_long_text
);
criterion_main!(benches);

View File

@@ -0,0 +1,38 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use tele_tui::utils::formatting::{format_date, format_timestamp, 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(timestamp));
}
});
});
}
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);

View File

@@ -0,0 +1,43 @@
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);