File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -3532,3 +3532,48 @@ mod tests {
3532
3532
assert_eq!(5, sum_len([s.as_slice()]));
3533
3533
}
3534
3534
}
3535
+
3536
+ #[cfg(test)]
3537
+ mod bench {
3538
+ use extra::test::BenchHarness;
3539
+ use str;
3540
+
3541
+ #[bench]
3542
+ fn is_utf8_100_ascii(bh: &mut BenchHarness) {
3543
+
3544
+ let s = bytes!(" Hello there, the quick brown fox jumped over the lazy dog! \
3545
+ Lorem ipsum dolor sit amet, consectetur. ");
3546
+
3547
+ assert_eq!(100, s.len());
3548
+ do bh.iter {
3549
+ str::is_utf8(s);
3550
+ }
3551
+ }
3552
+
3553
+ #[bench]
3554
+ fn is_utf8_100_multibyte(bh: &mut BenchHarness) {
3555
+ let s = bytes!(" 𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰");
3556
+ assert_eq!(100, s.len());
3557
+ do bh.iter {
3558
+ str::is_utf8(s);
3559
+ }
3560
+ }
3561
+
3562
+ #[bench]
3563
+ fn map_chars_100_ascii(bh: &mut BenchHarness) {
3564
+ let s = " HelloHelloHelloHelloHelloHelloHelloHelloHelloHello \
3565
+ HelloHelloHelloHelloHelloHelloHelloHelloHelloHello ";
3566
+ do bh.iter {
3567
+ s.map_chars(|c| ((c as uint) + 1) as char);
3568
+ }
3569
+ }
3570
+
3571
+ #[bench]
3572
+ fn map_chars_100_multibytes(bh: &mut BenchHarness) {
3573
+ let s = " 𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑\
3574
+ 𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑𐌀𐌖𐌋𐌄𐌑" ;
3575
+ do bh. iter {
3576
+ s. map_chars( |c| ( ( c as uint) + 1 ) as char ) ;
3577
+ }
3578
+ }
3579
+ }
You can’t perform that action at this time.
0 commit comments