#[bench] fn clone_frozen(b: &mut Bencher) { let bytes = BytesMut::from(&b"hello world 1234567890 and have a good byte 0987654321"[..])
.split()
.freeze();
b.iter(|| { for _ in0..1024 {
test::black_box(&bytes.clone());
}
})
}
#[bench] fn drain_write_drain(b: &mut Bencher) { let data = [0u8; 128];
b.iter(|| { letmut buf = BytesMut::with_capacity(1024); letmut parts = Vec::with_capacity(8);
for _ in0..8 {
buf.put(&data[..]);
parts.push(buf.split_to(128));
}
test::black_box(parts);
})
}
#[bench] fn fmt_write(b: &mut Bencher) { use std::fmt::Write; letmut buf = BytesMut::with_capacity(128); let s = "foo bar baz quux lorem ipsum dolor et";
b.bytes = s.len() as u64;
b.iter(|| { let _ = write!(buf, "{}", s);
test::black_box(&buf); unsafe {
buf.set_len(0);
}
})
}
#[bench] fn bytes_mut_extend(b: &mut Bencher) { letmut buf = BytesMut::with_capacity(256); let data = [33u8; 32];
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.