2 use test::{black_box, Bencher};
4 macro_rules! define_benches {
5 ($( fn $name: ident($arg: ident: &str) $body: block )+) => {
6 define_benches!(mod en_small, en::SMALL, $($name $arg $body)+);
7 define_benches!(mod en_medium, en::MEDIUM, $($name $arg $body)+);
8 define_benches!(mod en_large, en::LARGE, $($name $arg $body)+);
9 define_benches!(mod en_huge, en::HUGE, $($name $arg $body)+);
11 define_benches!(mod zh_small, zh::SMALL, $($name $arg $body)+);
12 define_benches!(mod zh_medium, zh::MEDIUM, $($name $arg $body)+);
13 define_benches!(mod zh_large, zh::LARGE, $($name $arg $body)+);
14 define_benches!(mod zh_huge, zh::HUGE, $($name $arg $body)+);
16 define_benches!(mod ru_small, ru::SMALL, $($name $arg $body)+);
17 define_benches!(mod ru_medium, ru::MEDIUM, $($name $arg $body)+);
18 define_benches!(mod ru_large, ru::LARGE, $($name $arg $body)+);
19 define_benches!(mod ru_huge, ru::HUGE, $($name $arg $body)+);
21 define_benches!(mod emoji_small, emoji::SMALL, $($name $arg $body)+);
22 define_benches!(mod emoji_medium, emoji::MEDIUM, $($name $arg $body)+);
23 define_benches!(mod emoji_large, emoji::LARGE, $($name $arg $body)+);
24 define_benches!(mod emoji_huge, emoji::HUGE, $($name $arg $body)+);
26 (mod $mod_name: ident, $input: expr, $($name: ident $arg: ident $body: block)+) => {
31 fn $name(bencher: &mut Bencher) {
33 bencher.bytes = input.len() as u64;
34 let mut input_s = input.to_string();
36 let $arg: &str = &black_box(&mut input_s);
46 fn case00_cur_libcore(s: &str) {
50 fn case01_old_libcore(s: &str) {
54 fn case02_iter_increment(s: &str) {
58 fn case03_manual_char_len(s: &str) {
63 fn cur_libcore(s: &str) -> usize {
67 fn utf8_is_cont_byte(byte: u8) -> bool {
70 fn old_libcore(s: &str) -> usize {
71 s.as_bytes().iter().filter(|&&byte| !utf8_is_cont_byte(byte)).count()
74 fn iterator_increment(s: &str) -> usize {
82 fn manual_char_len(s: &str) -> usize {