4 ms·
The author probably thinks that all versions are equally fast, but in fact they are just equally slow. Neither gcc 4.8 nor icc 14 can use vectorization for this
by Marat_Dukhan 13y ago
The author probably thinks that all versions are equally fast, but in fact they are just equally slow. Neither gcc 4.8 nor icc 14 can use vectorization for this loop (likely because of aliasing).
- pbsd 13y agoIt's not because of aliasing, it's because of the push_back call inside the inner loop, which may potentially have to allocate (in this case we know it doesn't, but the compiler does not). If you replace squareVec6 with vector<int> squareVec6(const vector<int>& v) { vector<int> result(v.size()); // preallocate // result.reserve(v.size()); transform(begin(v), end(v), begin(result), [](int i) { return i*i; }); return result; } the compiler will be happy to vectorize the loop.