【发布时间】:2010-10-23 20:56:50
【问题描述】:
我最近编写了一些代码 (ISO/ANSI C),但对它实现的糟糕性能感到惊讶。长话短说,原来罪魁祸首是floor() 函数。它不仅速度慢,而且没有矢量化(使用英特尔编译器,也就是 ICL)。
以下是对 2D 矩阵中的所有单元格执行地板的一些基准:
VC: 0.10
ICL: 0.20
将其与简单的演员比较:
VC: 0.04
ICL: 0.04
floor() 怎么会比简单的演员阵容慢那么多?!它基本上做同样的事情(除了负数)。
第二个问题:有人知道超快的floor() 实现吗?
PS:这是我进行基准测试的循环:
void Floor(float *matA, int *intA, const int height, const int width, const int width_aligned)
{
float *rowA=NULL;
int *intRowA=NULL;
int row, col;
for(row=0 ; row<height ; ++row){
rowA = matA + row*width_aligned;
intRowA = intA + row*width_aligned;
#pragma ivdep
for(col=0 ; col<width; ++col){
/*intRowA[col] = floor(rowA[col]);*/
intRowA[col] = (int)(rowA[col]);
}
}
}
【问题讨论】:
标签: c performance visual-c++ x86 intel