Re:Go vs. C vs. pypy/Python loop performance comparison
by karlheinz_py on Wednesday September 30, 2015 @04:47PM
(#10307037)
thanks for this insight, I've countered the problem with command line args. Now the C compiler can't guess how many loops will be made and therefore the test shows the same speed as C without using optimisation. But Go keeps having consistent speed, faster than C. I'm curious what kind of optimisation the Go compiler applies. See the update for further details..
Re:Go vs. C vs. pypy/Python loop performance comparison
by karlheinz_py on Wednesday September 30, 2015 @07:29PM
(#10308181)
Edit: I thought C optimisation wasn't working but I repeated the tests and now C keeps having the same speed with optimisation despite passing the number as command line argument. This also suggests that the value is not calculated at compile time..
If the optimizer is enabled, and the upper bound hard-coded, then the compiler pre-computes the loop. This is the entire code from llvmgcc:
Which means you are right - it's hard to beat a pre-computed constant.I think I owe you a penny.