| 1 |
// This file is part of ICU4X. For terms of use, please see the file |
| 2 |
// called LICENSE at the top level of the ICU4X source tree |
| 3 |
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
| 4 |
|
| 5 |
mod fixtures; |
| 6 |
|
| 7 |
use criterion::{ |
| 8 |
black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion, |
| 9 |
}; |
| 10 |
use icu_calendar::{Calendar, Date, Ref}; |
| 11 |
|
| 12 |
fn bench_calendar<C: Clone + Calendar>( |
| 13 |
group: &mut BenchmarkGroup<WallTime>, |
| 14 |
name: &str, |
| 15 |
calendar: C, |
| 16 |
) { |
| 17 |
let iso = Date::try_new_iso_date(2023, 8, 16).unwrap(); |
| 18 |
group.bench_function(name, |b| { |
| 19 |
b.iter(|| { |
| 20 |
let converted = black_box(iso).to_calendar(Ref(&calendar)); |
| 21 |
let year = black_box(converted.year().number); |
| 22 |
let month = black_box(converted.month().ordinal); |
| 23 |
let day = black_box(converted.day_of_month().0); |
| 24 |
black_box((converted, year, month, day)) |
| 25 |
}) |
| 26 |
}); |
| 27 |
} |
| 28 |
|
| 29 |
fn convert_benches(c: &mut Criterion) { |
| 30 |
let mut group = c.benchmark_group("convert"); |
| 31 |
|
| 32 |
bench_calendar(&mut group, "calendar/iso", icu::calendar::iso::Iso); |
| 33 |
|
| 34 |
#[cfg(feature = "bench")] |
| 35 |
bench_calendar( |
| 36 |
&mut group, |
| 37 |
"calendar/buddhist", |
| 38 |
icu::calendar::buddhist::Buddhist, |
| 39 |
); |
| 40 |
|
| 41 |
#[cfg(feature = "bench")] |
| 42 |
bench_calendar(&mut group, "calendar/coptic", icu::calendar::coptic::Coptic); |
| 43 |
|
| 44 |
#[cfg(feature = "bench")] |
| 45 |
bench_calendar( |
| 46 |
&mut group, |
| 47 |
"calendar/ethiopic", |
| 48 |
icu::calendar::ethiopian::Ethiopian::new(), |
| 49 |
); |
| 50 |
|
| 51 |
#[cfg(feature = "bench")] |
| 52 |
bench_calendar(&mut group, "calendar/indian", icu::calendar::indian::Indian); |
| 53 |
|
| 54 |
#[cfg(feature = "bench")] |
| 55 |
bench_calendar(&mut group, "calendar/julian", icu::calendar::julian::Julian); |
| 56 |
|
| 57 |
#[cfg(feature = "bench")] |
| 58 |
bench_calendar( |
| 59 |
&mut group, |
| 60 |
"calendar/chinese_calculating", |
| 61 |
icu::calendar::chinese::Chinese::new_always_calculating(), |
| 62 |
); |
| 63 |
|
| 64 |
#[cfg(feature = "bench")] |
| 65 |
bench_calendar( |
| 66 |
&mut group, |
| 67 |
"calendar/chinese_cached", |
| 68 |
icu::calendar::chinese::Chinese::new(), |
| 69 |
); |
| 70 |
|
| 71 |
#[cfg(feature = "bench")] |
| 72 |
bench_calendar( |
| 73 |
&mut group, |
| 74 |
"calendar/gregorian", |
| 75 |
icu::calendar::gregorian::Gregorian, |
| 76 |
); |
| 77 |
|
| 78 |
#[cfg(feature = "bench")] |
| 79 |
bench_calendar(&mut group, "calendar/hebrew", icu::calendar::hebrew::Hebrew); |
| 80 |
|
| 81 |
#[cfg(feature = "bench")] |
| 82 |
bench_calendar( |
| 83 |
&mut group, |
| 84 |
"calendar/islamic/observational", |
| 85 |
icu::calendar::islamic::IslamicObservational::new_always_calculating(), |
| 86 |
); |
| 87 |
|
| 88 |
#[cfg(feature = "bench")] |
| 89 |
bench_calendar( |
| 90 |
&mut group, |
| 91 |
"calendar/islamic/civil", |
| 92 |
icu::calendar::islamic::IslamicCivil::new(), |
| 93 |
); |
| 94 |
|
| 95 |
#[cfg(feature = "bench")] |
| 96 |
bench_calendar( |
| 97 |
&mut group, |
| 98 |
"calendar/islamic/ummalqura", |
| 99 |
icu::calendar::islamic::IslamicUmmAlQura::new_always_calculating(), |
| 100 |
); |
| 101 |
|
| 102 |
#[cfg(feature = "bench")] |
| 103 |
bench_calendar( |
| 104 |
&mut group, |
| 105 |
"calendar/islamic/tabular", |
| 106 |
icu::calendar::islamic::IslamicTabular::new(), |
| 107 |
); |
| 108 |
|
| 109 |
group.finish(); |
| 110 |
} |
| 111 |
|
| 112 |
criterion_group!(benches, convert_benches); |
| 113 |
criterion_main!(benches); |