bench: make some small updates to benchmarks

And also include updated benchmark results from `time 0.3.38`.
This commit is contained in:
Andrew Gallant 2025-03-05 18:29:06 -05:00
parent 98164d6263
commit bd4ef644e8
4 changed files with 55 additions and 42 deletions

View file

@ -21,7 +21,7 @@ path = "src/bench.rs"
[dependencies]
criterion = { version = "0.5.1", default-features = false }
jiff = { path = "..", features = ["tzdb-bundle-always"] }
jiff = { path = "..", features = ["static", "tzdb-bundle-always"] }
chrono = "0.4.38"
chrono-tz = "0.9.0"

View file

@ -128,6 +128,19 @@ fn to_timestamp_static(c: &mut Criterion) {
});
}
{
static TZ: jiff::tz::TimeZone = jiff::tz::get!("America/New_York");
benchmark(c, format!("{NAME}/bundled/jiff"), |b| {
b.iter(|| {
// The natural way to do this is `dt.to_zoned(..)`, but
// Jiff doesn't actually require one to materialize a `Zoned`
// to disambiguate a civil datetime.
let ts = bb(&TZ).to_timestamp(bb(DATETIME)).unwrap();
assert_eq!(ts.as_second(), STAMP);
})
});
}
#[cfg(unix)]
{
if let Ok(tz) = tzfile::Tz::named(TZNAME) {

View file

@ -28,14 +28,13 @@ pub(super) fn define(c: &mut Criterion) {
/// offset }` is the way to go.
fn fixed_offset_add_time(c: &mut Criterion) {
const NAME: &str = "zoned/fixed_offset_add_time";
const OFFSET: Offset = Offset::constant(-4);
const TZ: TimeZone = TimeZone::fixed(Offset::constant(-4));
const START: Timestamp = Timestamp::constant(1719755160, 0);
const EXPECTED: Timestamp =
Timestamp::constant(1719755160 + (24 * 60 * 60), 0);
let tz = TimeZone::fixed(OFFSET);
let start = START.to_zoned(tz.clone());
let expected = EXPECTED.to_zoned(tz.clone());
let start = START.to_zoned(TZ.clone());
let expected = EXPECTED.to_zoned(TZ.clone());
{
let span = 24.hours();
@ -94,12 +93,11 @@ fn fixed_offset_add_time(c: &mut Criterion) {
/// this operation is effectively free.
fn fixed_offset_to_civil_datetime(c: &mut Criterion) {
const NAME: &str = "zoned/fixed_offset_to_civil_datetime";
const OFFSET: Offset = Offset::constant(-4);
const TZ: TimeZone = TimeZone::fixed(Offset::constant(-4));
const STAMP: Timestamp = Timestamp::constant(1719755160, 0);
const EXPECTED: civil::DateTime = civil::date(2024, 6, 30).at(9, 46, 0, 0);
let tz = TimeZone::fixed(OFFSET);
let zdt = STAMP.to_zoned(tz.clone());
let zdt = STAMP.to_zoned(TZ.clone());
{
benchmark(c, format!("{NAME}/jiff"), |b| {
@ -143,11 +141,10 @@ fn fixed_offset_to_civil_datetime(c: &mut Criterion) {
/// conversion step.
fn fixed_offset_to_timestamp(c: &mut Criterion) {
const NAME: &str = "zoned/fixed_offset_to_timestamp";
const OFFSET: Offset = Offset::constant(-4);
const TZ: TimeZone = TimeZone::fixed(Offset::constant(-4));
const STAMP: Timestamp = Timestamp::constant(1719755160, 0);
let tz = TimeZone::fixed(OFFSET);
let zdt = STAMP.to_zoned(tz.clone());
let zdt = STAMP.to_zoned(TZ.clone());
{
benchmark(c, format!("{NAME}/jiff"), |b| {