This is my naive implementation of dot product:
float simple_dot(int N, float *A, float *B) {
float dot = 0;
for(int i = 0; i < N; ++i) {
dot += A[i] * B[i];
}
return dot;
}
And this is using the C++ library:
float library_dot(int N, float *A, float *B) {
return std::inner_product(A, A+N, B, 0);
}
I ran some benchmark(code is here https://github.com/ijklr/sse), and the library version is a lot slower.
My compiler flag is -Ofast -march=native