Debian Codegraph @

debian/rust-vendor/icu_calendar/benches/convert.rs

raw
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 use criterion::{
6 BenchmarkGroup, Criterion, black_box, criterion_group, criterion_main, measurement::WallTime,
7 };
8 use icu_calendar::{Calendar, Date};
9
10 #[macro_use]
11 mod common;
12
13 fn bench_calendar<C: Copy + Calendar>(
14 group: &mut BenchmarkGroup<WallTime>,
15 name: &str,
16 calendar: C,
17 ) {
18 let iso = Date::try_new_iso(2023, 8, 16).unwrap();
19 group.bench_function(name, |b| {
20 b.iter(|| {
21 let converted = black_box(iso).to_calendar(calendar);
22 let year = black_box(converted.year());
23 let month = black_box(converted.month());
24 let day = black_box(converted.day_of_month());
25 black_box((converted, year, month, day))
26 })
27 });
28 }
29
30 fn convert_benches(c: &mut Criterion) {
31 let mut group = c.benchmark_group("convert");
32
33 bench_all_calendars!(group, bench_calendar);
34
35 group.finish();
36 }
37
38 criterion_group!(benches, convert_benches);
39 criterion_main!(benches);