about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2019-12-19 17:53:53 -0500
committerGitHub <noreply@github.com>2019-12-19 17:53:53 -0500
commit9d1baaf11d0469b23763b9bd878296e5728f1c26 (patch)
treee39882fcac8e026ad7f682025a1ce0c8bd1ead8d /src/liballoc
parent939beb58d32c0aa0cf351e72d87b5f38aab9b7d4 (diff)
parentc6321a4df897ab9f32224f493c9e3ee8890cb443 (diff)
Rollup merge of #67281 - llogiq:nonoverlapping-insert, r=alexcrichton
add string.insert benchmarks

This adds benchmarks for `String::insert` and `String::insert_str`
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/benches/string.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/liballoc/benches/string.rs b/src/liballoc/benches/string.rs
index 2933014cb58..599c8b16828 100644
--- a/src/liballoc/benches/string.rs
+++ b/src/liballoc/benches/string.rs
@@ -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
+    })
+}