mirror of
https://github.com/chronotope/chrono.git
synced 2025-10-02 23:36:17 +00:00
Add formatting benchmarks
This commit is contained in:
parent
13ad948ef9
commit
ea9398eb0d
@ -146,6 +146,36 @@ fn bench_parse_strftime_localized(c: &mut Criterion) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bench_format(c: &mut Criterion) {
|
||||||
|
let dt = Local::now();
|
||||||
|
c.bench_function("bench_format", |b| b.iter(|| format!("{}", dt.format("%Y-%m-%d %H-%M-%S"))));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_format_with_items(c: &mut Criterion) {
|
||||||
|
let dt = Local::now();
|
||||||
|
let items: Vec<_> = StrftimeItems::new("%Y-%m-%d %H-%M-%S").collect();
|
||||||
|
c.bench_function("bench_format_with_items", |b| {
|
||||||
|
b.iter(|| format!("{}", dt.format_with_items(items.iter())))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_format_manual(c: &mut Criterion) {
|
||||||
|
let dt = Local::now();
|
||||||
|
c.bench_function("bench_format_manual", |b| {
|
||||||
|
b.iter(|| {
|
||||||
|
format!(
|
||||||
|
"{}-{:02}-{:02} {:02}:{:02}:{:02}",
|
||||||
|
dt.year(),
|
||||||
|
dt.month(),
|
||||||
|
dt.day(),
|
||||||
|
dt.hour(),
|
||||||
|
dt.minute(),
|
||||||
|
dt.second()
|
||||||
|
)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
criterion_group!(
|
criterion_group!(
|
||||||
benches,
|
benches,
|
||||||
bench_datetime_parse_from_rfc2822,
|
bench_datetime_parse_from_rfc2822,
|
||||||
@ -157,6 +187,9 @@ criterion_group!(
|
|||||||
bench_num_days_from_ce,
|
bench_num_days_from_ce,
|
||||||
bench_get_local_time,
|
bench_get_local_time,
|
||||||
bench_parse_strftime,
|
bench_parse_strftime,
|
||||||
|
bench_format,
|
||||||
|
bench_format_with_items,
|
||||||
|
bench_format_manual,
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "unstable-locales")]
|
#[cfg(feature = "unstable-locales")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user