Skip to content

Commit

Permalink
chore: Add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
nakedible authored Oct 14, 2023
1 parent 4255987 commit 8b9a5af
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions benches/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ fn rand_date() -> (i32, u8, u8) {
(y, m, d)
}

fn rand_packed() -> i32 {
datealgo::date_to_packed(rand_date())
}

fn rand_secs() -> i64 {
fastrand::i64(datealgo::RD_SECONDS_MIN..=datealgo::RD_SECONDS_MAX)
}
Expand Down Expand Up @@ -77,6 +81,12 @@ fn rand_iwd() -> (i32, u8, u8) {
}

fn bench_basic(c: &mut Criterion) {
c.bench_function("date_to_packed", |b| {
b.iter_custom(bencher(rand_date, |d| datealgo::date_to_packed(black_box(d))))
});
c.bench_function("packed_to_date", |b| {
b.iter_custom(bencher(rand_packed, |p| datealgo::packed_to_date(black_box(p))))
});
c.bench_function("rd_to_date", |b| {
b.iter_custom(bencher(rand_rd, |rd| datealgo::rd_to_date(black_box(rd))))
});
Expand Down

0 comments on commit 8b9a5af

Please sign in to comment.