> I'm sorry, could you clarify what you mean by "eliminate" here.
Most compilers will eliminate code if they can tell the results of a calculation are never used. Benchmarks typically call some function and discard the result. If you aren't careful, the compiler can often optimize away your entire benchmark down to nothing.
This is why you often see benchmarks that look like:
int average(a, b) {
return (a + b) / 2;
}
main() {
int sum;
for (int i = 0; i < 100000; i++) {
for (int j = 0; j < 100000; j++) {
sum += average(i, j);
}
}
if (sum != 123) printf("!");
}
Instead of: int average(a, b) {
return (a + b) / 2;
}
main() {
for (int i = 0; i < 100000; i++) {
for (int j = 0; j < 100000; j++) {
average(i, j);
}
}
}