-1
考虑下面的代码:缓存未命中?我怎么能看到?
for (int i=0; i<n; i++)
{
counter += myArray[i];
}
,循环展开版本:
for (int i=0; i<n; i+=4)
{
counter1 += myArray[i+0];
counter2 += myArray[i+1];
counter3 += myArray[i+2];
counter4 += myArray[i+3];
}
total = counter1+ counter2 + counter3+ counter4;
- 为什么我们在第一个版本高速缓存未命中?
- 第二个版本的确比第一个版本有更好的表现吗?为什么?
问候
是什么让你认为存在的第一个版本高速缓存未命中? – templatetypedef 2012-04-08 19:40:08
我不知道还会有差别很大...... – 2012-04-08 19:40:10
气味像功课太多... – m0skit0 2012-04-08 19:40:13