After executing this:
use std::sync::Arc;
use std::time::Instant;
fn main() {
let cap = 100000000;
let b0 = vec![0; cap];
let now = Instant::now();
Arc::new(b0);
println!("T0: {:?}", now.elapsed());
let c0 = vec![0; cap];
let _ = c0.clone(); // <- this makes it slow
let now = Instant::now();
Arc::new(c0);
println!("T1: {:?}", now.elapsed());
}
The result is: T0: 5.971µs T1: 26.69574ms
Why the second Arc::new is slow if we clone c0 before?
Edit:
I tested it with:
- Windows 10, rust 1.44.1 debug
- Linux, rust 1.47-nightly release
- Linux, rust 1.18
- MacOS, rust 1.44.0-nightly release
T1's time increases linearly with the vector size.