Closed
Description
This is a case where two almost identical functions have very different performance, because the slice version is autovectorized and the vector version is not. Note that specialization is involved, but both cases use exactly the same code path, for the slice iterator.
#![crate_type="lib"]
#[no_mangle]
pub fn dot_s(xs: &[u32], ys: &[u32]) -> u32 {
let mut s = 0;
for (x, y) in xs.iter().zip(ys) {
s += x * y;
}
s
}
#[no_mangle]
pub fn dot_v(xs: &Vec<u32>, ys: &Vec<u32>) -> u32 {
let mut s = 0;
for (x, y) in xs.iter().zip(ys) {
s += x * y;
}
s
}
Using rustc 1.14.0-nightly (289f3a4 2016-09-29)
Note: The Vec vs slice difference is sometimes visible in actual inline use of .zip in code, depending on exact context.