Label Cloud

Wednesday, December 13, 2006

A VERY cool example of compiler optimization

http://blogs.msdn.com/abhinaba/archive/2006/12/13/why-can-we-only-use-constants-in-a-switch-case-statement.aspx

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


Share/Save/Bookmark

No comments:

Directory of Computers/Tech Blogs