C optimisation

Posted by in Random

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:

  • 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…

— This is a really old post published originally on my blogspot blog


A little experiment: If you find this post and ad below useful, please check the ad out :-)