aboutsummaryrefslogtreecommitdiff
path: root/benches/bytes_mut.rs
diff options
context:
space:
mode:
authorGravatar Sean McArthur <sean@seanmonstar.com> 2019-11-12 14:52:02 -0800
committerGravatar GitHub <noreply@github.com> 2019-11-12 14:52:02 -0800
commitb32f6298e289958986b68982788562f3c097f8fc (patch)
treec838443425e327474eb79565bf94bbeaad7411a9 /benches/bytes_mut.rs
parent856ed7c43de8eca457cc5e00b7fdcc3edeb4c52a (diff)
downloadbytes-b32f6298e289958986b68982788562f3c097f8fc.tar.gz
bytes-b32f6298e289958986b68982788562f3c097f8fc.tar.zst
bytes-b32f6298e289958986b68982788562f3c097f8fc.zip
Improve performance of `BytesMut::reserve` (#313)
Makes the short-circuit checks inline-able, and the moves the actual reserving code to an inner function.
Diffstat (limited to 'benches/bytes_mut.rs')
-rw-r--r--benches/bytes_mut.rs21
1 files changed, 18 insertions, 3 deletions
diff --git a/benches/bytes_mut.rs b/benches/bytes_mut.rs
index 8e49f9c..ded1d14 100644
--- a/benches/bytes_mut.rs
+++ b/benches/bytes_mut.rs
@@ -141,10 +141,25 @@ fn fmt_write(b: &mut Bencher) {
})
}
+#[bench]
+fn bytes_mut_extend(b: &mut Bencher) {
+ let mut buf = BytesMut::with_capacity(256);
+ let data = [33u8; 32];
+
+ b.bytes = data.len() as u64 * 4;
+ b.iter(|| {
+ for _ in 0..4 {
+ buf.extend(&data);
+ }
+ test::black_box(&buf);
+ unsafe { buf.set_len(0); }
+ });
+}
+
// BufMut for BytesMut vs Vec<u8>
#[bench]
-fn put_bytes_mut(b: &mut Bencher) {
+fn put_slice_bytes_mut(b: &mut Bencher) {
let mut buf = BytesMut::with_capacity(256);
let data = [33u8; 32];
@@ -174,7 +189,7 @@ fn put_u8_bytes_mut(b: &mut Bencher) {
}
#[bench]
-fn put_vec(b: &mut Bencher) {
+fn put_slice_vec(b: &mut Bencher) {
let mut buf = Vec::<u8>::with_capacity(256);
let data = [33u8; 32];
@@ -204,7 +219,7 @@ fn put_u8_vec(b: &mut Bencher) {
}
#[bench]
-fn put_vec_extend(b: &mut Bencher) {
+fn put_slice_vec_extend(b: &mut Bencher) {
let mut buf = Vec::<u8>::with_capacity(256);
let data = [33u8; 32];