Inspired by this question,
Now visible only for users with > 10k rep
I came up with the following code:
$cat loop.c
int main(
If you are trying to make a compiler do a certain unit or, well, benchmark of work, then you need to fool it into thinking the result of the work will actually be used.
One way to do this is to write a function in one file, compile it, and then call it with the setup from another file. No compiler can anticipate what will be compiled in the future.
Without that, it's just sort of a contest between default optimization levels and has no useful significance.
Your program does absolutely nothing so this says nothing about the performance of both languages. The only thing it tells you is if your compiler is able to figure this out and therefore completely skips your program.
To make it do "something" you would have to print every increment to stdout. If you print only the end result a good compiler could optimize your program to a statement that just prints this result and skips the whole "computation".
There are some things you need to control for here: