]> git.lizzy.rs Git - rust.git/blobdiff - src/liballoc/benches/string.rs
rustc_span: return an impl Iterator instead of a Vec from macro_backtrace.
[rust.git] / src / liballoc / benches / string.rs
index 2933014cb58e918461795f09d8fd0416aaeae670..5c95160ba2d14dba82ea7a57b4fef7b64ef45f88 100644 (file)
@@ -1,5 +1,5 @@
 use std::iter::repeat;
-use test::Bencher;
+use test::{black_box, Bencher};
 
 #[bench]
 fn bench_with_capacity(b: &mut Bencher) {
@@ -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
+    })
+}