From c2b08675ed8e4d8e0e1b613c4794c924e563d2af Mon Sep 17 00:00:00 2001 From: Nuutti Kotivuori Date: Sat, 14 Oct 2023 18:48:27 +0000 Subject: [PATCH] Add alternative `next_date` and `prev_date` benches --- benches/compare.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/benches/compare.rs b/benches/compare.rs index 981d11a..96a7116 100644 --- a/benches/compare.rs +++ b/benches/compare.rs @@ -143,6 +143,17 @@ mod datealgo_alt { ((day as u32 + (13 * mm - 1) / 5 + yy + yy / 4 - yy / 100 + yy / 400 + 6) % 7 + 1) as u8 } + #[inline] + pub const fn next_date((y, m, d): (i32, u8, u8)) -> (i32, u8, u8) { + let rd = datealgo::date_to_rd((y, m, d)); + datealgo::rd_to_date(rd + 1) + } + + #[inline] + pub const fn prev_date((y, m, d): (i32, u8, u8)) -> (i32, u8, u8) { + let rd = datealgo::date_to_rd((y, m, d)); + datealgo::rd_to_date(rd - 1) + } #[inline] pub const fn is_leap_year(y: i32) -> bool { y % 4 == 0 && (y % 100 != 0 || y % 400 == 0) @@ -897,6 +908,9 @@ fn bench_next_date(c: &mut Criterion) { group.bench_function("datealgo", |b| { b.iter_custom(bencher(rand_date, |d| datealgo::next_date(black_box(d)))) }); + group.bench_function("datealgo_alt", |b| { + b.iter_custom(bencher(rand_date, |d| datealgo_alt::next_date(black_box(d)))) + }); group.bench_function("chrono", |b| { b.iter_custom(bencher(chrono::rand_date, |d| chrono::next_date(black_box(d)))) }); @@ -911,6 +925,9 @@ fn bench_prev_date(c: &mut Criterion) { group.bench_function("datealgo", |b| { b.iter_custom(bencher(rand_date, |d| datealgo::prev_date(black_box(d)))) }); + group.bench_function("datealgo_alt", |b| { + b.iter_custom(bencher(rand_date, |d| datealgo_alt::prev_date(black_box(d)))) + }); group.bench_function("chrono", |b| { b.iter_custom(bencher(chrono::rand_date, |d| chrono::prev_date(black_box(d)))) });