From e48a22584be039adb3651b50962421a3a989bcb6 Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Wed, 17 Jul 2024 15:23:32 -0700 Subject: [PATCH] Remove bench code for old datetime formatters --- components/datetime/benches/datetime.rs | 372 +------------------- components/datetime/benches/fixtures/mod.rs | 5 +- components/datetime/tests/mock.rs | 1 + 3 files changed, 3 insertions(+), 375 deletions(-) diff --git a/components/datetime/benches/datetime.rs b/components/datetime/benches/datetime.rs index d4786dd67f1..ea0a72e9b27 100644 --- a/components/datetime/benches/datetime.rs +++ b/components/datetime/benches/datetime.rs @@ -13,15 +13,11 @@ use icu_datetime::neo_skeleton::{NeoDateSkeleton, NeoSkeletonLength, NeoTimeComp use icu_datetime::neo_skeleton::{NeoDateTimeComponents, NeoDateTimeSkeleton}; #[cfg(feature = "experimental")] use icu_datetime::options::length; -use std::fmt::Write; use icu_calendar::{DateTime, Gregorian}; #[cfg(feature = "experimental")] use icu_datetime::DateTimeFormatterOptions; -use icu_datetime::TypedDateTimeFormatter; -use icu_datetime::{time_zone::TimeZoneFormatterOptions, TypedZonedDateTimeFormatter}; use icu_locale_core::Locale; -use icu_timezone::CustomTimeZone; #[cfg(feature = "experimental")] use writeable::TryWriteable; @@ -31,51 +27,6 @@ mod mock; fn datetime_benches(c: &mut Criterion) { let mut group = c.benchmark_group("datetime"); - let mut bench_datetime_with_fixture = |name, file| { - let fxs = serde_json::from_str::(file).unwrap(); - group.bench_function(&format!("datetime_{name}"), |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_gregorian_from_str(value)) - .collect(); - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().expect("Failed to parse locale."); - let options = fixtures::get_options(&setup.options).unwrap(); - #[cfg(feature = "experimental")] - let dtf = { - TypedDateTimeFormatter::::try_new_experimental( - &locale.into(), - options, - ) - .expect("Failed to create TypedDateTimeFormatter.") - }; - #[cfg(not(feature = "experimental"))] - let dtf = { - TypedDateTimeFormatter::::try_new(&locale.into(), options) - .expect("Failed to create TypedDateTimeFormatter.") - }; - - let mut result = String::new(); - - for dt in &datetimes { - let fdt = dtf.format(dt); - write!(result, "{fdt}").expect("Failed to write to date time format."); - result.clear(); - } - } - } - }) - }); - }; - - bench_datetime_with_fixture("lengths", include_str!("fixtures/tests/lengths.json")); - - #[cfg(feature = "experimental")] - bench_datetime_with_fixture("components", include_str!("fixtures/tests/components.json")); - #[cfg(feature = "experimental")] let mut bench_neoneo_datetime_with_fixture = |name, file| { let fxs = serde_json::from_str::(file).unwrap(); @@ -153,330 +104,9 @@ fn datetime_benches(c: &mut Criterion) { #[cfg(feature = "experimental")] bench_neoneo_datetime_with_fixture("lengths", include_str!("fixtures/tests/lengths.json")); - let fxs = serde_json::from_str::(include_str!( - "fixtures/tests/lengths_with_zones.json" - )) - .unwrap(); - group.bench_function("zoned_datetime_overview", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec<(DateTime, CustomTimeZone)> = fx - .values - .iter() - .map(|value| mock::parse_zoned_gregorian_from_str(value)) - .collect(); - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = TypedZonedDateTimeFormatter::::try_new( - &locale.into(), - options, - TimeZoneFormatterOptions::default(), - ) - .unwrap(); - - let mut result = String::new(); - - for dt in &datetimes { - let fdt = dtf.format(&dt.0, &dt.1); - write!(result, "{fdt}").unwrap(); - result.clear(); - } - } - } - }) - }); + // TODO: Add back benches that read the other fixture files group.finish(); - - #[cfg(feature = "bench")] - { - use writeable::Writeable; - - let mut group = c.benchmark_group("datetime"); - - let fxs = - serde_json::from_str::(include_str!("fixtures/tests/lengths.json")) - .unwrap(); - group.bench_function("TypedDateTimeFormatter/format_to_write", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = - TypedDateTimeFormatter::::try_new(&locale.into(), options) - .unwrap(); - - let mut scratch = String::new(); - - for dt in &datetimes { - let _ = dtf.format(dt).write_to(&mut scratch); - scratch.clear(); - } - } - } - }) - }); - - group.bench_function("TypedDateTimeFormatter/format_to_string", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = - TypedDateTimeFormatter::::try_new(&locale.into(), options) - .unwrap(); - - for dt in &datetimes { - let _ = dtf.format_to_string(dt); - } - } - } - }) - }); - - group.bench_function("FormattedDateTime/format", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = - TypedDateTimeFormatter::::try_new(&locale.into(), options) - .unwrap(); - - let mut result = String::new(); - - for dt in &datetimes { - let fdt = dtf.format(dt); - write!(result, "{fdt}").unwrap(); - result.clear(); - } - } - } - }) - }); - - group.bench_function("FormattedDateTime/to_string", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = - TypedDateTimeFormatter::::try_new(&locale.into(), options) - .unwrap(); - - for dt in &datetimes { - let fdt = dtf.format(dt); - let _ = fdt.to_string(); - } - } - } - }) - }); - - group.bench_function("FormattedDateTime/write_to_string", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec> = fx - .values - .iter() - .map(|value| mock::parse_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = - TypedDateTimeFormatter::::try_new(&locale.into(), options) - .unwrap(); - - for dt in &datetimes { - let fdt = dtf.format(dt); - let _ = fdt.write_to_string(); - } - } - } - }) - }); - - let fxs = serde_json::from_str::(include_str!( - "fixtures/tests/lengths_with_zones.json" - )) - .unwrap(); - group.bench_function("TypedZonedDateTimeFormatter/format_to_write", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec<(DateTime, CustomTimeZone)> = fx - .values - .iter() - .map(|value| mock::parse_zoned_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = TypedZonedDateTimeFormatter::::try_new( - &locale.into(), - options, - TimeZoneFormatterOptions::default(), - ) - .unwrap(); - - let mut scratch = String::new(); - - for dt in &datetimes { - let _ = dtf.format(&dt.0, &dt.1).write_to(&mut scratch); - scratch.clear(); - } - } - } - }) - }); - - group.bench_function("TypedZonedDateTimeFormatter/format_to_string", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec<(DateTime, CustomTimeZone)> = fx - .values - .iter() - .map(|value| mock::parse_zoned_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = TypedZonedDateTimeFormatter::::try_new( - &locale.into(), - options, - TimeZoneFormatterOptions::default(), - ) - .unwrap(); - - for dt in &datetimes { - let _ = dtf.format_to_string(&dt.0, &dt.1); - } - } - } - }) - }); - - group.bench_function("FormattedZonedDateTime/format", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec<(DateTime, CustomTimeZone)> = fx - .values - .iter() - .map(|value| mock::parse_zoned_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = TypedZonedDateTimeFormatter::::try_new( - &locale.into(), - options, - TimeZoneFormatterOptions::default(), - ) - .unwrap(); - - let mut result = String::new(); - - for dt in &datetimes { - let fdt = dtf.format(&dt.0, &dt.1); - write!(result, "{fdt}").unwrap(); - result.clear(); - } - } - } - }) - }); - - group.bench_function("FormattedZonedDateTime/to_string", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec<(DateTime, CustomTimeZone)> = fx - .values - .iter() - .map(|value| mock::parse_zoned_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = TypedZonedDateTimeFormatter::::try_new( - &locale.into(), - options, - TimeZoneFormatterOptions::default(), - ) - .unwrap(); - - for dt in &datetimes { - let fdt = dtf.format(&dt.0, &dt.1); - let _ = fdt.to_string(); - } - } - } - }) - }); - - group.bench_function("FormattedZonedDateTime/write_to_string", |b| { - b.iter(|| { - for fx in &fxs.0 { - let datetimes: Vec<(DateTime, CustomTimeZone)> = fx - .values - .iter() - .map(|value| mock::parse_zoned_gregorian_from_str(value)) - .collect(); - - for setup in &fx.setups { - let locale: Locale = setup.locale.parse().unwrap(); - let options = fixtures::get_options(&setup.options).unwrap(); - let dtf = TypedZonedDateTimeFormatter::::try_new( - &locale.into(), - options, - TimeZoneFormatterOptions::default(), - ) - .unwrap(); - - for dt in &datetimes { - let fdt = dtf.format(&dt.0, &dt.1); - let _ = fdt.write_to_string(); - } - } - } - }) - }); - - group.finish(); - } } criterion_group!(benches, datetime_benches); diff --git a/components/datetime/benches/fixtures/mod.rs b/components/datetime/benches/fixtures/mod.rs index 7e2df0a9954..6300baa853e 100644 --- a/components/datetime/benches/fixtures/mod.rs +++ b/components/datetime/benches/fixtures/mod.rs @@ -58,9 +58,6 @@ pub struct PatternsFixture(pub Vec); pub fn get_options(input: &TestOptions) -> Option { match input { TestOptions::Length(bag) => Some((*bag).into()), - #[cfg(feature = "experimental")] - TestOptions::Components(bag) => Some((*bag).into()), - #[cfg(not(feature = "experimental"))] - TestOptions::Components(_) => None, + TestOptions::Components(_) => todo!(), } } diff --git a/components/datetime/tests/mock.rs b/components/datetime/tests/mock.rs index 86affe96db2..f3f93147359 100644 --- a/components/datetime/tests/mock.rs +++ b/components/datetime/tests/mock.rs @@ -77,6 +77,7 @@ pub fn parse_gregorian_from_str(input: &str) -> DateTime { /// mock::parse_zoned_gregorian_from_str("2020-10-14T13:21:00+05:30") /// .expect("Failed to parse a zoned datetime."); /// ``` +#[allow(dead_code)] // due to inclusion in benches folder pub fn parse_zoned_gregorian_from_str(input: &str) -> (DateTime, CustomTimeZone) { let idx = input.rfind(&['+', '-', '\u{2212}', 'Z']).unwrap(); #[allow(clippy::indexing_slicing)] // valid index