Hi,
I assume this is expected behaviour to most, but it went against my 
expected behaviour so thought I would share.
I was benchmarking some code and in the inner loop discovered that:

if true {
  funcA()
} else {
  funcB()
}


was slower than:
//if true {
  funcA()
//} else {
//  funcB()
//}


On the one hand: DUH! of course.
On the other I expected these kind of basic compile time optimisations to 
be a thing.

So I assume the Go compiler doesn't try and do this analysis in a Compile 
time vs Execution time tradeoff. It may also be that the compiler does try 
and do this, but it didn't recognise it in my code.

Anyway Hope that is useful to someone. It has certainly changed the way I 
will write my (profiled) inner loops.

Chris

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to