Software development industry analysis by Larry O'Brien, the former editor of Software Development and Computer Language
Sunday, April 18, 2004

  Which one of these three loops is the most efficient? How can I prove the answer?

I've listed the source code below. The three loops are:

  1. Foreach over an int array
  2. Simple for over an int array
  3. For over an int array, hoisting out the length value

...

The third option is to be avoided. The JIT looks for the pattern in version #2, and knows how to optimize it. If you pull the value out into a temporary, it may not optimize it. Of course, you know that because you've been measuring your important scenarios...

Sunday, April 18, 2004 6:20:37 AM (Hawaiian Standard Time, UTC-10:00) |  Disqus link  | Knowing#
Search
About Larry...
Flickr photostream
Subscribe: RSS 2.0 Atom 1.0
Popular Articles
Programming Sabre with Java, C#, and XML
Genetic Programming in C#
15 Exercises To Know A Programming Language
Top 10 Things I've Learned About Computers From the Movies and Any Episode of "24"
Recently Published Articles
HI
KonaKoder
Categories
Archive
Admin Login
Sign In
Toolroll