• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Collections: Chapter 2: Decrement Performance

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Author
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic