Debian Codegraph @

debian/missing-sources/icu_collections/benches/inv_list.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::{criterion_group, criterion_main, Criterion};
6 use icu_collections::codepointinvlist::CodePointInversionList;
7 use std::char;
8
9 fn uniset_bench(c: &mut Criterion) {
10 let best_ex = [0x41, 0x46];
11 let best_sample = CodePointInversionList::try_from_u32_inversion_list_slice(&best_ex).unwrap();
12 let worst_ex: Vec<u32> = (0x0..((char::MAX as u32) + 1)).collect();
13 let worst_sample =
14 CodePointInversionList::try_from_u32_inversion_list_slice(&worst_ex).unwrap();
15
16 c.bench_function("uniset/overview", |b| {
17 #[expect(clippy::suspicious_map)]
18 b.iter(|| {
19 best_sample
20 .iter_chars()
21 .map(|ch| best_sample.contains(ch))
22 .count();
23 worst_sample
24 .iter_chars()
25 .map(|ch| worst_sample.contains(ch))
26 .count();
27 best_sample
28 .iter_chars()
29 .map(|ch| best_sample.contains_range('A'..ch))
30 .count();
31 worst_sample
32 .iter_chars()
33 .take(100)
34 .map(|ch| worst_sample.contains_range(char::from_u32(0x0).unwrap()..ch))
35 .count();
36 })
37 });
38
39 {
40 let mut group = c.benchmark_group("uniset/contains");
41 group.bench_with_input("best", &best_sample, |b, sample| {
42 b.iter(|| sample.iter_chars().map(|ch| sample.contains(ch)))
43 });
44 group.bench_with_input("worst", &worst_sample, |b, sample| {
45 b.iter(|| sample.iter_chars().take(100).map(|ch| sample.contains(ch)))
46 });
47 group.finish();
48
49 let mut group = c.benchmark_group("uniset/contains_range");
50 group.bench_with_input("best", &best_sample, |b, sample| {
51 b.iter(|| sample.iter_chars().map(|ch| sample.contains_range('A'..ch)))
52 });
53 group.bench_with_input("worst", &worst_sample, |b, sample| {
54 b.iter(|| {
55 sample
56 .iter_chars()
57 .take(100)
58 .map(|ch| sample.contains_range(char::from_u32(0x0).unwrap()..ch))
59 })
60 });
61 group.finish();
62 }
63 }
64
65 criterion_group!(benches, uniset_bench);
66 criterion_main!(benches);