We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cda3490 commit a913fc6Copy full SHA for a913fc6
src/libcollections/string.rs
@@ -1408,4 +1408,20 @@ mod tests {
1408
let _ = String::from_utf8_lossy(s.as_slice());
1409
});
1410
}
1411
+
1412
+ #[bench]
1413
+ fn bench_exact_size_shrink_to_fit(b: &mut Bencher) {
1414
+ let s = "Hello there, the quick brown fox jumped over the lazy dog! \
1415
+ Lorem ipsum dolor sit amet, consectetur. ";
1416
+ // ensure our operation produces an exact-size string before we benchmark it
1417
+ let mut r = String::with_capacity(s.len());
1418
+ r.push_str(s);
1419
+ assert_eq!(r.len(), r.capacity());
1420
+ b.iter(|| {
1421
1422
1423
+ r.shrink_to_fit();
1424
+ r
1425
+ });
1426
+ }
1427
0 commit comments