DEV Community

Discussion on: Do function calls hinder performance?

Collapse
 
pgradot profile image
Pierre Gradot

What option are using to control you compiler's optimization level?

I believe your code is optimized at all. See on Compiler Explorer.

Collapse
 
pnx profile image
Yuttapichai Kerdcharoen

Thank you for pointing this out. I was using -O0 when I wrote this blog.

When I applied -O1, the compiler optimized func to just a single add instruction as on the Compiler Explorer you attached.

Honestly, the flag -O1 also changes the bunch of func(&x) and x++ in both cases into a single mov instruction with an immediate, in which both cases use the same instructions with -O1 (and so are -O2 and -O3, I believe) at the end of the day.

Collapse
 
pgradot profile image
Pierre Gradot

You should do your timing measures again, I guess you see almost no difference with -O1