Label Cloud

Wednesday, December 13, 2006

A VERY cool example of compiler optimization

Reading Microsoft Blogs, I saw a great example of compiler optimization. Apparently, C# compiler is able to optimize case statement that is based on string constants. Once the number of cases reaches a specific level (example was with 7 cases including default) , the compiler switched from using if statement, to pre-populating values into a dictionary and doing a value lookup.

It really is amazing how good compilers are these day and proves once again

  • Do not try to outsmart the compiler
  • Do not over-optimize too early
  • Profile early, Profile Often


No comments:

Directory of Computers/Tech Blogs