for this program,vtune/call graph also got a different result:
the purpose is to compare 'if-else' with 'func pointer array'
and measure the branch predict impact.
the program output:
test caseA
branchA time=2510484704
test caseB
branchB time=1934092704
but the vtune show a different result:
time caseB spent much more time than caseA(about 5:1)
why call graph shows such differences?
----code----------------------
inline void HandleFuncA0(int y)
{ count=y+3;}
inline void HandleFuncA1(int y)
{ count=y+7;}
inline void HandleFuncA2(int y)
{ count=y-2;}
...
inline void BranchA2(int x)
{
if (x>RANGE*9/10)
HandleFuncA1(x);
else if (x>RANGE*8/10)
HandleFuncA2(x);
...
}
inline void BranchB(int x)
{
array
(x); //array[0]=HandleFuncA0,array[1]=HandleFuncA1,...etc
}
void test_caseA()
{
printf("test caseAn");
timespec l_startTime,l_endTime,l_interval;
int ret;
long long i_period;
clock_gettime(CLOCK_REALTIME,&l_startTime);
for (int i =0;i{
BranchA2(inp[i%3000]); //inp[] has been initialized with rand()
}
clock_gettime(CLOCK_REALTIME,&l_endTime);
ret = delta_t(&l_interval, &l_startTime, &l_endTime);
i_period = l_interval.tv_sec*1000000000+l_interval.tv_nsec;
printf("branchA time=%un",i_period);
}
void test_case4B()
{
.../same as test_caseA
for (xxx)
BranchB(inp[i%3000]); //inp[] has been initialized with rand()
...
}