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.
Thank you for pointing this out. I was using
-O0when I wrote this blog.When I applied
-O1, the compiler optimizedfuncto just a singleaddinstruction as on the Compiler Explorer you attached.Honestly, the flag
-O1also changes the bunch offunc(&x)andx++in both cases into a singlemovinstruction with an immediate, in which both cases use the same instructions with-O1(and so are-O2and-O3, I believe) at the end of the day.You should do your timing measures again, I guess you see almost no difference with
-O1