Why Java is running faster than C here?

后端 未结 9 712
甜味超标
甜味超标 2021-01-02 11:55

Inspired by this question,

Now visible only for users with > 10k rep

I came up with the following code:

$cat loop.c 
int main(          


        
9条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 12:32

    The Java JIT compiler is smart enough to optimize the loop away, while your C compiler seems to have most of the optimizations turned off.

    So you are really comparing the time to start up the Java machine with the time it takes unoptimized C code to count to 2 billion.

提交回复
热议问题