Skip to content

Commit

Permalink
Add benchmark for DateTime::format_with
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Apr 6, 2024
1 parent f0ba6d8 commit 45d7f15
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bench/benches/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,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| {
Expand Down Expand Up @@ -235,6 +251,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,
bench_naivedate_add_signed,
Expand Down

0 comments on commit 45d7f15

Please sign in to comment.