• 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

Optimization

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone suggest a resource for learning about optimization?
A lot of my nitpicking errors seem to be about optimization. I undrestand in general that creating an object such as a String has a lot more overhead than working with an int or other primitive type. But I have been searching for something that discusses this in more detail.
For example:
"creating an object uses x processor clock cycles, while declaring a primitive variable and assigning a value to it uses y processor clock cycles", or something along these lines.
In Java 4B (Say) I was trying to decide whether to convert a long integer back to a String and pass it as a parameter to a method (1 line of code), or to type in the five lines of code from the method at this point, thus avoiding the conversion to a String and the method call.
Thank you
Peter Berquist
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would it be unreasonable to have a method that took the long as an argument?
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a good book about performance "Java Performance Tuning" by Jack Shirazi. The whole chapter is devoted to object creation. This is what "Object creation statistics" section said:
"For example, on a medium Pentium II, with heap space pregrown so that garbage collection does not have to kick in, you can get around half a million to a million simple objects created per second. If the objects are very simple, even more can be garbage-collected in one second. On the other hand, if the objects are complex, with references to other objects, and include arrays (like Vector and StringBuffer) and nonminimal constructors, the statistics plummet to less than a quarter of a million created per second, and garbage collection can drop way down to below 100,000 objects per second."
[Just found that this chapter is available online
http://www.ora.com/catalog/javapt/chapter/ch04.html ]
James W. Cooper "Is Java fast enough?" in his article in JavaPro quotes experiment when the same computations were performed in "Fortran-style" and "Object-oriented style" and statistics shows that "object-orientation slows processing by a factor of 10-20".
http://www.fawcette.com/javapro/2002_03/magazine/columns/javatecture/default_pf.asp
However, for most applications even performance degradation by a factor of 10-20 is perfectly acceptable. Readability and maintainability of code is what really matters.
Finally, there is a simple technique you can use to calculate any statistics you want:

(Real Truth can be more complex than that, because GC can interrupt object creation cycle if too many are created, or compiler can perform some smart optimizations etc., but as a general technique this should work)
[ July 28, 2002: Message edited by: Mapraputa Is ]
 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A great topic. This is the stuff good programmers know and, average programmers ignore.
I strongly recommend Peter Haggar's book, Practical Java.

--Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic