The application that I'm dealing with has a large number of a if-statements with the characteristics that in any one execution, only one of the branches is executed 90% of the time.
Now, I can test the impact of branch prediction on a single if-statement for a specific CPU by doing something like this :-
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
int a;
cin>>a;
srand(a);
int b;
long count=0;
for (int i=0; i<10000; i++) {
for (int j=0; j<65535; j++) {
b = rand() % 30 + 1;
if (b > 15) // This can be changed to get statistics for different %-ages
count += (b+10);
}
}
cout << count <<"\n";
}
My question is, is there a way of testing the scalability and impact of branch prediction with multiple if-statements in an actual large application for a given CPU?
Basically, I want to be able to figure out how much branch mispredicts are costing on various CPUs and their impact on the application.