[Solved] Why is swapping elements of a []float64 in Go faster than swapping elements of a Vec in Rust?

Could the Rust program be written in an idiomatic way, to execute faster? Yes. To create a vector with a few elements, use the vec![] macro: let mut work: Vec<f64> = vec![0.0, 1.0]; for _x in 1..100000000 { work.swap(0, 1); } So is this code faster? Yes. Have a look at what assembly is generated: … Read more