Skip to content

Commit

Permalink
Add size tests for main datetime types (unicode-org#4513)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Jan 6, 2024
1 parent 39a01a4 commit 415989a
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 0 deletions.
10 changes: 10 additions & 0 deletions components/datetime/src/any/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::helpers::size_test;
use crate::provider::calendar::*;
use crate::{calendar, options::length, raw};
use crate::{input::DateInput, DateTimeError, FormattedDateTime};
Expand All @@ -18,6 +19,13 @@ use icu_provider::prelude::*;
use icu_provider::DataLocale;
use writeable::Writeable;

size_test!(
DateFormatter,
date_formatter_size,
pinned = 4600,
nightly = 4456
);

/// [`DateFormatter`] is a formatter capable of formatting
/// dates from any calendar, selected at runtime. For the difference between this and [`TypedDateFormatter`](crate::TypedDateFormatter),
/// please read the [crate root docs][crate].
Expand All @@ -28,6 +36,8 @@ use writeable::Writeable;
/// For that reason, one should think of the process of formatting a date in two steps - first, a computational
/// heavy construction of [`DateFormatter`], and then fast formatting of [`DateTime`](icu_calendar::DateTime) data using the instance.
///
#[doc = date_formatter_size!()]
///
/// [`icu_datetime`]: crate
///
/// # Examples
Expand Down
10 changes: 10 additions & 0 deletions components/datetime/src/any/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::helpers::size_test;
use crate::provider::{calendar::*, date_time::PatternSelector};
use crate::{calendar, options::DateTimeFormatterOptions, raw, DateFormatter, TimeFormatter};
use crate::{input::DateTimeInput, DateTimeError, FormattedDateTime};
Expand All @@ -18,6 +19,13 @@ use icu_provider::prelude::*;
use icu_provider::DataLocale;
use writeable::Writeable;

size_test!(
DateTimeFormatter,
date_time_formatter_size,
pinned = 5480,
nightly = 5208
);

/// [`DateTimeFormatter`] is a formatter capable of formatting
/// date/times from any calendar, selected at runtime. For the difference between this and [`TypedDateTimeFormatter`](crate::TypedDateTimeFormatter),
/// please read the [crate root docs][crate].
Expand All @@ -28,6 +36,8 @@ use writeable::Writeable;
/// For that reason, one should think of the process of formatting a date in two steps - first, a computational
/// heavy construction of [`DateTimeFormatter`], and then fast formatting of [`DateTime`](icu_calendar::DateTime) data using the instance.
///
#[doc = date_time_formatter_size!()]
///
/// [`icu_datetime`]: crate
///
/// # Examples
Expand Down
10 changes: 10 additions & 0 deletions components/datetime/src/any/zoned_datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use alloc::string::String;

use icu_provider::prelude::*;

use crate::helpers::size_test;
use crate::input::{DateTimeInput, ExtractedDateTimeInput, TimeZoneInput};
use crate::provider::{self, calendar::*, date_time::PatternSelector};
use crate::time_zone::TimeZoneFormatterOptions;
Expand All @@ -21,6 +22,13 @@ use icu_decimal::provider::DecimalSymbolsV1Marker;
use icu_plurals::provider::OrdinalV1Marker;
use writeable::Writeable;

size_test!(
ZonedDateTimeFormatter,
zoned_date_time_formatter_size,
pinned = 6520,
nightly = 6248
);

/// [`ZonedDateTimeFormatter`] is a formatter capable of formatting
/// date/times with time zones from any calendar, selected at runtime. For the difference between this and [`TypedZonedDateTimeFormatter`](crate::TypedZonedDateTimeFormatter),
/// please read the [crate root docs][crate].
Expand All @@ -39,6 +47,8 @@ use writeable::Writeable;
/// first, a computationally heavy construction of [`ZonedDateTimeFormatter`], and then fast formatting
/// of the data using the instance.
///
#[doc = zoned_date_time_formatter_size!()]
///
/// # Examples
///
/// Using a GMT time zone:
Expand Down
28 changes: 28 additions & 0 deletions components/datetime/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! Central to this is the [`TypedDateTimeFormatter`].
use crate::{
helpers::size_test,
options::{length, preferences, DateTimeFormatterOptions},
provider::calendar::{TimeLengthsV1Marker, TimeSymbolsV1Marker},
provider::date_time::PatternSelector,
Expand All @@ -24,13 +25,22 @@ use crate::{
DateTimeError, FormattedDateTime,
};

size_test!(
TimeFormatter,
time_formatter_size,
pinned = 1328,
nightly = 1200
);

/// [`TimeFormatter`] is a structure of the [`icu_datetime`] component that provides time formatting only.
/// When constructed, it uses data from the [data provider], selected locale and provided preferences to
/// collect all data necessary to format any time into that locale.
///
/// For that reason, one should think of the process of formatting a time in two steps - first, a computational
/// heavy construction of [`TimeFormatter`], and then fast formatting of [`DateTimeInput`] data using the instance.
///
#[doc = time_formatter_size!()]
///
/// [`icu_datetime`]: crate
/// [`TypedDateTimeFormatter`]: crate::datetime::TimeFormatter
///
Expand Down Expand Up @@ -178,6 +188,13 @@ impl TimeFormatter {
}
}

size_test!(
TypedDateFormatter<icu_calendar::Gregorian>,
typed_date_formatter_size,
pinned = 4544,
nightly = 4400
);

/// [`TypedDateFormatter`] is a formatter capable of formatting
/// dates from a calendar selected at compile time. For the difference between this
/// and [`DateFormatter`](crate::DateFormatter), please read the [crate root docs][crate].
Expand All @@ -188,6 +205,8 @@ impl TimeFormatter {
/// For that reason, one should think of the process of formatting a date in two steps - first, a computational
/// heavy construction of [`TypedDateFormatter`], and then fast formatting of [`DateInput`] data using the instance.
///
#[doc = typed_date_formatter_size!()]
///
/// [`icu_datetime`]: crate
///
/// # Examples
Expand Down Expand Up @@ -390,6 +409,13 @@ impl<C: CldrCalendar> TypedDateFormatter<C> {
}
}

size_test!(
TypedDateTimeFormatter<icu_calendar::Gregorian>,
typed_date_time_formatter_size,
pinned = 5424,
nightly = 5152
);

/// [`TypedDateTimeFormatter`] is a formatter capable of formatting
/// date/times from a calendar selected at compile time. For the difference between this
/// and [`DateTimeFormatter`](crate::DateTimeFormatter), please read the [crate root docs][crate].
Expand All @@ -400,6 +426,8 @@ impl<C: CldrCalendar> TypedDateFormatter<C> {
/// For that reason, one should think of the process of formatting a date in two steps - first, a computational
/// heavy construction of [`TypedDateTimeFormatter`], and then fast formatting of [`DateInput`] data using the instance.
///
#[doc = typed_date_time_formatter_size!()]
///
/// [`icu_datetime`]: crate
/// [`TypedDateTimeFormatter`]: crate::datetime::TypedDateTimeFormatter
///
Expand Down
11 changes: 11 additions & 0 deletions components/datetime/src/format/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::calendar::CldrCalendar;
use crate::error::DateTimeError as Error;
use crate::external_loaders::*;
use crate::fields::{self, FieldLength, FieldSymbol};
use crate::helpers::size_test;
use crate::input;
use crate::input::DateInput;
use crate::input::DateTimeInput;
Expand Down Expand Up @@ -115,7 +116,17 @@ impl<M: KeyedDataMarker> DataProvider<M> for PhantomProvider {
}
}

size_test!(
TypedDateTimeNames<icu_calendar::Gregorian>,
typed_date_time_names_size,
pinned = 504,
nightly = 488
);

/// A low-level type that formats datetime patterns with localized symbols.
/// The calendar should be chosen at compile time.
///
#[doc = typed_date_time_names_size!()]
///
/// <div class="stab unstable">
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways,
Expand Down
2 changes: 2 additions & 0 deletions components/datetime/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ macro_rules! size_test {
}
};
}

pub(crate) use size_test;
41 changes: 41 additions & 0 deletions components/datetime/src/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ macro_rules! gen_any_buffer_constructors_with_external_loader {
};
}

size_test!(
TypedNeoDateFormatter<icu_calendar::Gregorian>,
typed_neo_date_formatter_size,
pinned = 512,
nightly = 496
);

/// [`TypedNeoDateFormatter`] can format dates from a calendar selected at compile time.
///
/// For the difference between this and [`DateFormatter`](crate::DateFormatter), please
/// read the [crate root docs][crate].
///
#[doc = typed_neo_date_formatter_size!()]
///
/// <div class="stab unstable">
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature
Expand Down Expand Up @@ -231,6 +245,18 @@ impl<'a> FormattedNeoDate<'a> {
}
}

size_test!(
NeoTimeFormatter,
neo_time_formatter_size,
pinned = 464,
nightly = 448
);

/// [`NeoTimeFormatter`] can format times of day.
/// It supports both 12-hour and 24-hour formats.
///
#[doc = neo_time_formatter_size!()]
///
/// <div class="stab unstable">
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature
Expand Down Expand Up @@ -385,6 +411,21 @@ impl<'a> FormattedNeoTime<'a> {
}
}

size_test!(
TypedNeoDateTimeFormatter<icu_calendar::Gregorian>,
neo_date_time_formatter_size,
pinned = 584,
nightly = 568
);

/// [`TypedNeoDateTimeFormatter`] can format dates with times of day. The dates must be in
/// a calendar system determined at compile time.
///
/// For the difference between this and [`DateTimeFormatter`](crate::DateTimeFormatter), please
/// read the [crate root docs][crate].
///
#[doc = neo_date_time_formatter_size!()]
///
/// <div class="stab unstable">
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways,
/// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature
Expand Down
5 changes: 5 additions & 0 deletions components/datetime/src/neo_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
use core::str::FromStr;

use crate::helpers::size_test;
use crate::pattern::{runtime, PatternError, PatternItem};

size_test!(DateTimePattern, date_time_pattern_size, 32);

/// A pattern for formatting a datetime in a calendar.
///
/// Most clients should use [`DateTimeFormatter`] instead of directly
Expand All @@ -18,6 +21,8 @@ use crate::pattern::{runtime, PatternError, PatternItem};
/// 1. From a custom pattern string: [`DateTimePattern::try_from_pattern_str`]
/// 2. From a formatted datetime: [`FormattedNeoDateTime::pattern`]
///
#[doc = date_time_pattern_size!()]
///
/// # Examples
///
/// Create a pattern from a custom string and compare it to one from data:
Expand Down

0 comments on commit 415989a

Please sign in to comment.