| 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 |
#[macro_export] |
| 6 |
macro_rules! overview { |
| 7 |
($c:expr, $struct:ident, $data_str:expr, $compare:expr) => { |
| 8 |
$c.bench_function("overview", |b| { |
| 9 |
b.iter(|| { |
| 10 |
let mut values = vec![]; |
| 11 |
for s in $data_str { |
| 12 |
let value: Result<$struct, _> = black_box(s).parse(); |
| 13 |
values.push(value.expect("Parsing failed")); |
| 14 |
} |
| 15 |
let _ = values |
| 16 |
.iter() |
| 17 |
.filter(|&v| v.normalizing_eq($compare)) |
| 18 |
.count(); |
| 19 |
|
| 20 |
values |
| 21 |
.iter() |
| 22 |
.map(|v| v.to_string()) |
| 23 |
.collect::<Vec<String>>() |
| 24 |
}) |
| 25 |
}); |
| 26 |
}; |
| 27 |
} |
| 28 |
|
| 29 |
#[macro_export] |
| 30 |
macro_rules! construct { |
| 31 |
($c:expr, $struct:ident, $struct_name:expr, $data_str:expr) => { |
| 32 |
$c.bench_function($struct_name, |b| { |
| 33 |
b.iter(|| { |
| 34 |
for s in $data_str { |
| 35 |
let _: Result<$struct, _> = black_box(s).parse(); |
| 36 |
} |
| 37 |
}) |
| 38 |
}); |
| 39 |
}; |
| 40 |
} |
| 41 |
|
| 42 |
#[macro_export] |
| 43 |
macro_rules! to_string { |
| 44 |
($c:expr, $struct:ident, $struct_name:expr, $data:expr) => { |
| 45 |
$c.bench_function($struct_name, |b| { |
| 46 |
b.iter(|| { |
| 47 |
for s in $data { |
| 48 |
let _ = black_box(s).to_string(); |
| 49 |
} |
| 50 |
}) |
| 51 |
}); |
| 52 |
$c.bench_function(std::concat!($struct_name, "/writeable"), |b| { |
| 53 |
use writeable::Writeable; |
| 54 |
b.iter(|| { |
| 55 |
for s in $data { |
| 56 |
let _ = black_box(s).write_to_string(); |
| 57 |
} |
| 58 |
}) |
| 59 |
}); |
| 60 |
}; |
| 61 |
} |
| 62 |
|
| 63 |
#[macro_export] |
| 64 |
macro_rules! compare_struct { |
| 65 |
($c:expr, $struct:ident, $struct_name:expr, $data1:expr, $data2:expr) => { |
| 66 |
$c.bench_function(BenchmarkId::new("struct", $struct_name), |b| { |
| 67 |
b.iter(|| { |
| 68 |
for (lid1, lid2) in $data1.iter().zip($data2.iter()) { |
| 69 |
let _ = black_box(lid1) == black_box(lid2); |
| 70 |
} |
| 71 |
}) |
| 72 |
}); |
| 73 |
}; |
| 74 |
} |
| 75 |
|
| 76 |
#[macro_export] |
| 77 |
macro_rules! compare_str { |
| 78 |
($c:expr, $struct:ident, $struct_name:expr, $data1:expr, $data2:expr) => { |
| 79 |
$c.bench_function(BenchmarkId::new("str", $struct_name), |b| { |
| 80 |
b.iter(|| { |
| 81 |
for (lid, s) in $data1.iter().zip($data2.iter()) { |
| 82 |
let _ = black_box(lid).normalizing_eq(&black_box(s)); |
| 83 |
} |
| 84 |
}) |
| 85 |
}); |
| 86 |
$c.bench_function(BenchmarkId::new("strict_cmp", $struct_name), |b| { |
| 87 |
b.iter(|| { |
| 88 |
for (lid, s) in $data1.iter().zip($data2.iter()) { |
| 89 |
let _ = black_box(lid).strict_cmp(&black_box(s).as_str().as_bytes()); |
| 90 |
} |
| 91 |
}) |
| 92 |
}); |
| 93 |
}; |
| 94 |
} |
| 95 |
|
| 96 |
#[macro_export] |
| 97 |
macro_rules! canonicalize { |
| 98 |
($c:expr, $struct:ident, $struct_name:expr, $data:expr) => { |
| 99 |
$c.bench_function($struct_name, |b| { |
| 100 |
b.iter(|| { |
| 101 |
for s in $data { |
| 102 |
let _ = black_box(s).to_string(); |
| 103 |
} |
| 104 |
for s in $data { |
| 105 |
let _ = $struct::canonicalize(black_box(s)); |
| 106 |
} |
| 107 |
}) |
| 108 |
}); |
| 109 |
}; |
| 110 |
} |