Skip to content

Commit 372a886

Browse files
committed
---
yaml --- r: 67192 b: refs/heads/master c: e5cbede h: refs/heads/master v: v3
1 parent 727f244 commit 372a886

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 786318f61b3d41238937d194970d2aaac34886cd
2+
refs/heads/master: e5cbede103fca018089b113ec35f0cf863df7106
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/libstd/str.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,3 +3532,48 @@ mod tests {
35323532
assert_eq!(5, sum_len([s.as_slice()]));
35333533
}
35343534
}
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+
}

0 commit comments

Comments
 (0)