Some checks failed
ci/woodpecker/pr/check Pipeline failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
use tele_tui::utils::formatting::{format_date, format_timestamp_with_tz, 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);
|