Skip to content

Commit

Permalink
Rollup merge of rust-lang#67281 - llogiq:nonoverlapping-insert, r=ale…
Browse files Browse the repository at this point in the history
…xcrichton

add string.insert benchmarks

This adds benchmarks for `String::insert` and `String::insert_str`
  • Loading branch information
Mark-Simulacrum authored Dec 19, 2019
2 parents 939beb5 + c6321a4 commit 9d1baaf
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/liballoc/benches/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

0 comments on commit 9d1baaf

Please sign in to comment.