Skip to content

Commit

Permalink
Remove bench code for old datetime formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Jul 18, 2024
1 parent 14e86d3 commit e48a225
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 375 deletions.
372 changes: 1 addition & 371 deletions components/datetime/benches/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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::<fixtures::Fixture>(file).unwrap();
group.bench_function(&format!("datetime_{name}"), |b| {
b.iter(|| {
for fx in &fxs.0 {
let datetimes: Vec<DateTime<Gregorian>> = 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::<Gregorian>::try_new_experimental(
&locale.into(),
options,
)
.expect("Failed to create TypedDateTimeFormatter.")
};
#[cfg(not(feature = "experimental"))]
let dtf = {
TypedDateTimeFormatter::<Gregorian>::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::<fixtures::Fixture>(file).unwrap();
Expand Down Expand Up @@ -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::<fixtures::Fixture>(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<Gregorian>, 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::<Gregorian>::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::<fixtures::Fixture>(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<DateTime<Gregorian>> = 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::<Gregorian>::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<DateTime<Gregorian>> = 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::<Gregorian>::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<DateTime<Gregorian>> = 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::<Gregorian>::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<DateTime<Gregorian>> = 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::<Gregorian>::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<DateTime<Gregorian>> = 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::<Gregorian>::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::<fixtures::Fixture>(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<Gregorian>, 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::<Gregorian>::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<Gregorian>, 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::<Gregorian>::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<Gregorian>, 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::<Gregorian>::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<Gregorian>, 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::<Gregorian>::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<Gregorian>, 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::<Gregorian>::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);
Expand Down
Loading

0 comments on commit e48a225

Please sign in to comment.