From 0ab97077ca22a87a2e3494a9be3e4ce95033c775 Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Sat, 8 Jul 2023 17:20:04 +0200 Subject: [PATCH] Add benchmark for `DateTime::format_with` --- benches/chrono.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/benches/chrono.rs b/benches/chrono.rs index 3f74923af2..4034ef2686 100644 --- a/benches/chrono.rs +++ b/benches/chrono.rs @@ -161,6 +161,22 @@ fn bench_parse_strftime_localized(c: &mut Criterion) { }); } +fn bench_format_to_string(c: &mut Criterion) { + let dt = Local::now(); + c.bench_function("bench_format_to_string", |b| { + b.iter(|| black_box(dt).format_to_string("%Y-%m-%dT%H:%M:%S%.f%:z")) + }); +} + +fn bench_format_with(c: &mut Criterion) { + let dt = Local::now(); + let fmt_items: Vec<_> = StrftimeItems::new("%Y-%m-%dT%H:%M:%S%.f%:z").collect(); + let formatter = DateTime::formatter(&fmt_items).unwrap(); + c.bench_function("bench_format_with", |b| { + b.iter(|| format!("{}", black_box(dt).format_with(&formatter))) + }); +} + fn bench_format(c: &mut Criterion) { let dt = Local::now(); c.bench_function("bench_format", |b| { @@ -209,6 +225,8 @@ criterion_group!( bench_get_local_time, bench_parse_strftime, bench_format, + bench_format_to_string, + bench_format_with, bench_format_with_items, bench_format_manual, );