Skip to content

Commit 2aaa351

Browse files
committed
Add benchmark for DateTime::format_with
1 parent 5061941 commit 2aaa351

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

bench/benches/chrono.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ fn bench_parse_strftime_localized(c: &mut Criterion) {
170170
});
171171
}
172172

173+
fn bench_format_to_string(c: &mut Criterion) {
174+
let dt = Local::now();
175+
c.bench_function("bench_format_to_string", |b| {
176+
b.iter(|| black_box(dt).format_to_string("%Y-%m-%dT%H:%M:%S%.f%:z"))
177+
});
178+
}
179+
180+
fn bench_format_with(c: &mut Criterion) {
181+
let dt = Local::now();
182+
let fmt_items: Vec<_> = StrftimeItems::new("%Y-%m-%dT%H:%M:%S%.f%:z").collect();
183+
let formatter = DateTime::formatter(&fmt_items).unwrap();
184+
c.bench_function("bench_format_with", |b| {
185+
b.iter(|| format!("{}", black_box(dt).format_with(&formatter)))
186+
});
187+
}
188+
173189
fn bench_format(c: &mut Criterion) {
174190
let dt = Local::now();
175191
c.bench_function("bench_format", |b| {
@@ -235,6 +251,8 @@ criterion_group!(
235251
bench_get_local_time,
236252
bench_parse_strftime,
237253
bench_format,
254+
bench_format_to_string,
255+
bench_format_with,
238256
bench_format_with_items,
239257
bench_format_manual,
240258
bench_naivedate_add_signed,

0 commit comments

Comments
 (0)