cpp-cheat/c/interactive/branch_prediction_and_patterns_perf.c
2015-07-06 11:59:37 +02:00

29 lines
438 B
C

/*
Measure the performance of each call with: TODO
http://igoro.com/archive/fast-and-slow-if-statements-branch-prediction-in-modern-processors/
*/
#include "common.h"
const long N = 1000000000;
void f(long p) {
long sum = 0;
for (long i = 0; i < N; i++)
if (!(i & p))
sum++;
}
int main() {
f(INT_MIN);
f(-1);
f(1);
f(2);
f(3);
f(4);
f(8);
f(16);
return EXIT_SUCCESS;
}