diff options
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/str.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 125df156ed0..6876bf3da7c 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -3532,3 +3532,48 @@ mod tests { assert_eq!(5, sum_len([s.as_slice()])); } } + +#[cfg(test)] +mod bench { + use extra::test::BenchHarness; + use str; + + #[bench] + fn is_utf8_100_ascii(bh: &mut BenchHarness) { + + let s = bytes!("Hello there, the quick brown fox jumped over the lazy dog! \ + Lorem ipsum dolor sit amet, consectetur. "); + + assert_eq!(100, s.len()); + do bh.iter { + str::is_utf8(s); + } + } + + #[bench] + fn is_utf8_100_multibyte(bh: &mut BenchHarness) { + let s = bytes!("ππππππΰΈΰΈ£Ψ―ΩΩΨ© Ψ§ΩΩΩΩΨͺΰΈΰΈ¨ΰΉΰΈΰΈ’δΈεπ πΏπ»ππΉπ»π°"); + assert_eq!(100, s.len()); + do bh.iter { + str::is_utf8(s); + } + } + + #[bench] + fn map_chars_100_ascii(bh: &mut BenchHarness) { + let s = "HelloHelloHelloHelloHelloHelloHelloHelloHelloHello\ + HelloHelloHelloHelloHelloHelloHelloHelloHelloHello"; + do bh.iter { + s.map_chars(|c| ((c as uint) + 1) as char); + } + } + + #[bench] + fn map_chars_100_multibytes(bh: &mut BenchHarness) { + let s = "ππππππππππππππππππππππππππππππππππππππππππππππππππ\ + ππππππππππππππππππππππππππππππππππππππππππππππππππ"; + do bh.iter { + s.map_chars(|c| ((c as uint) + 1) as char); + } + } +} |
