关于Vtune测量branch misprediction的问题
haojn 2008-04-08 04:55:49 作归并排序的时候想测量一下分支预测失败对归并时性能的影响,于是在vtune中增加branch misprediction performance impact。测量后,该数值居然为0,但理论上讲因为热点部分的分支都是数据相关的,分支预测不可能有这么高。
另外,我特地写了个绝对是数据相关的分支程序:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define N 10000000
int aa[N];
int main( void )
{
int i;
srand( (unsigned)time( NULL ) );
for (i=0;i<N;i++){
int a,b;
a=rand();
b=rand();
if (a>b){
aa[i]=a;
}
else{
aa[i]=b;
}
}
}
因为都是随机数据,我认为分支预测错误率在if语句块50%左右才对,但测量的结果branch misprediction performance impact只有0.77%
是vtune哪里设置错了么?如何才能正确地观察到分支预测错误率?
谢谢!