Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Collections: Chapter 2: Decrement Performance

 
Yuri Gadow
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question for Mr. Zukowski (or anyone familiar with the book), regarding chapter two of his book (which I read on the JDC.) In it, he states that counting down (as in for (;;i--)) is faster than counting up, "more significantly with the 1.3 release" (hint). Running your timing example code does, in fact, show numbers that support this hypothesis. However, reversing the order in which the count directions are tested, or better yet testing them separately in different VM instances yields numbers that seem to tell a slightly different story. That story being that whichever loop is run second is significantly faster, regardless of its count direction or the preceding loops direction � assuming HotSpot is on (hint). But perhaps I missed the java.exe option -runFaster?
Seriously though, was this hypothesis not tested to eliminate variables like runtime optimizations and memory profiles - or am I missing something here?
 
John Zukowski
Author
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently I didn't test out the timing well enough across platforms. I do have to say that the second version does not always run faster though. I've heard back from someone on Solaris that leaving the order as is, their decreasing Delta numbers came up 4x slower, as the second loop.
------------------
John Zukowski Author of "Definitive Guide to Swing for Java 2" and "Java Collections"
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to Jack Shirazi in the book "Java Performance Tuning":
"Comparison to 0 is faster than comparisons to most other numbers. The VM has optimizations for comparisons to the integers -1, 0, 1, 2, 3, 4, and 5. So rewriting loops to make the test comparison against 0 may be faster."
However, he also adds: "Only non-JIT VMs and HotSpot showed improvements by rewriting the loop."
I ran several tests through a JIT compiler and saw no difference of any kind.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wierdly enough, the JVM which I (am forced to) use on a DEC Unix Alpha box does support a non-standard "-fast" command line option. It makes writing scripts to work with any VM a pain in the proverbial.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic