top | item 37071403

(no title)

throwawayadvsec | 2 years ago

it's unlikely that there is a difference

compilers are usually optimizing these kind of statements so they end up similar or identical

if you wanna be sure, make two loops running a few million times with random if else / switches and time them

discuss

order

Someone|2 years ago

I agree it’s unlikely, but that may tell you that the compiler can compile the two with similar performance, but won’t tell you whether the compiler will do so in your code.

If you want to be sure, you have to benchmark your production code with production data.

Look at the generated machine code may also help, but can be difficult, as the generated code may be different, but of similar performance, and judging whether two instruction sequences have similar performance is hard on modern hardware, with its out-of-order executing, multiple layers of caches, etc.

verdverm|2 years ago

Golang now has PGO, so you can capture traces to make programs faster next build