Skip to content

Commit

Permalink
Add formatting benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker authored and djc committed Jun 27, 2023
1 parent 13ad948 commit ea9398e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions benches/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
benches,
bench_datetime_parse_from_rfc2822,
Expand All @@ -157,6 +187,9 @@ criterion_group!(
bench_num_days_from_ce,
bench_get_local_time,
bench_parse_strftime,
bench_format,
bench_format_with_items,
bench_format_manual,
);

#[cfg(feature = "unstable-locales")]
Expand Down

0 comments on commit ea9398e

Please sign in to comment.