小编ijk*_*klr的帖子

为什么std :: inner_product比天真的实现慢?

这是我对dot产品的天真实现:

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;
}
Run Code Online (Sandbox Code Playgroud)

这是使用C++库:

float library_dot(int N, float *A, float *B) {
    return std::inner_product(A, A+N, B, 0);
}
Run Code Online (Sandbox Code Playgroud)

我运行了一些基准测试(代码在这里https://github.com/ijklr/sse),库版本慢很多.我的编译器标志是-Ofast -march=native

c++ floating-point sse numeric fast-math

3
推荐指数
1
解决办法
637
查看次数

标签 统计

c++ ×1

fast-math ×1

floating-point ×1

numeric ×1

sse ×1