mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Add benchmarks for string::insert(_str)
This commit is contained in:
parent
c8ea4ace92
commit
c6321a4df8
@ -122,3 +122,43 @@ fn bench_to_string(b: &mut Bencher) {
|
|||||||
Lorem ipsum dolor sit amet, consectetur. ";
|
Lorem ipsum dolor sit amet, consectetur. ";
|
||||||
b.iter(|| s.to_string())
|
b.iter(|| s.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_insert_char_short(b: &mut Bencher) {
|
||||||
|
let s = "Hello, World!";
|
||||||
|
b.iter(|| {
|
||||||
|
let mut x = String::from(s);
|
||||||
|
black_box(&mut x).insert(6, black_box(' '));
|
||||||
|
x
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_insert_char_long(b: &mut Bencher) {
|
||||||
|
let s = "Hello, World!";
|
||||||
|
b.iter(|| {
|
||||||
|
let mut x = String::from(s);
|
||||||
|
black_box(&mut x).insert(6, black_box('❤'));
|
||||||
|
x
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_insert_str_short(b: &mut Bencher) {
|
||||||
|
let s = "Hello, World!";
|
||||||
|
b.iter(|| {
|
||||||
|
let mut x = String::from(s);
|
||||||
|
black_box(&mut x).insert_str(6, black_box(" "));
|
||||||
|
x
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn bench_insert_str_long(b: &mut Bencher) {
|
||||||
|
let s = "Hello, World!";
|
||||||
|
b.iter(|| {
|
||||||
|
let mut x = String::from(s);
|
||||||
|
black_box(&mut x).insert_str(6, black_box(" rustic "));
|
||||||
|
x
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user