Skip to content

Commit

Permalink
Add alternative next_date and prev_date benches
Browse files Browse the repository at this point in the history
  • Loading branch information
nakedible authored Oct 14, 2023
1 parent c528c04 commit c2b0867
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions benches/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))))
});
Expand All @@ -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))))
});
Expand Down

0 comments on commit c2b0867

Please sign in to comment.