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:

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.


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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top