Rollup merge of #67281 - llogiq:nonoverlapping-insert, r=alexcrichton

add string.insert benchmarks

This adds benchmarks for `String::insert` and `String::insert_str`
This commit is contained in:
Mark Rousskov 2019-12-19 17:53:53 -05:00 committed by GitHub
commit 9d1baaf11d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 0 deletions

View File

@ -122,3 +122,43 @@ fn bench_to_string(b: &mut Bencher) {
Lorem ipsum dolor sit amet, consectetur. ";
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
})
}