You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I imagine that something is happening along the way which is preventing this from becoming a memcpy.
~ $ cat foo.rs
use std::vec;
fn main() {
let a = vec::from_fn(50 * 1024 * 1024, |_| 0u8);
for _ in range(0, 30) {
a.to_owned();
}
}
~ $ cat bar.rs
use std::vec;
fn main() {
let a = vec::from_fn(50 * 1024 * 1024, |_| 0u8);
for _ in range(0, 30) {
let mut b = vec::with_capacity::<u8>(50 * 1024 * 1024);
unsafe {
vec::raw::set_len(&mut b, 50 * 1024 * 1024);
}
vec::bytes::copy_memory(b, a, a.len());
}
}
~ $ rustc -O foo.rs
~ $ rustc -O bar.rs
~ $ time ./foo
./foo 3.41s user 0.20s system 99% cpu 3.624 total
~ $ time ./bar
./bar 0.38s user 0.20s system 97% cpu 0.593 total
The memcpy is a 6x speedup compared to to_owned()
The text was updated successfully, but these errors were encountered:
I imagine that something is happening along the way which is preventing this from becoming a memcpy.
The memcpy is a 6x speedup compared to
to_owned()
The text was updated successfully, but these errors were encountered: