C Optimisation - 2005 style
1 min read

C Optimisation - 2005 style

C Optimisation - 2005 style

TL;DR: This post is about an experience I had in 2004 and it’s part of my consolidating technical posts I wrote in time. It may or may not be relevant to today’s technologies.

I was trying to optimize a bit of code and found out that 2 if() statements are quicker than a case with true/false. and an if/else case is WAY quicker!!!

All with various optimisation levels (from nothing to O3 to O3 + architecture optimisations). Odd. one might believe that the switch/case statement would create a static jump table once (@ compilation/linking time) and use it... Guess it's more to it than the goto table... The times for optimised code O3 + p4 optimisations:

Instruction time
case 2.163650 sec
if + if 1.621306 sec
if/else 0.584177 sec

I guess once a second it won't make a huge difference in the grand scheme of things...

Original post here.