It's difficult to calculate timing for very simple operations because of the
optimizations being done by modern JITs. They also have changed a lot over the
last year or two - the figures given in Bruce's book were for earlier JVMs, and
most have improved a lot for current JITs and adaptive JVM/JITs. Even the page
Steven pointed at is a little out of date, and that's just a few months old.

I'm trying to put together a more comprehensive set of pages I can periodically
update. For right now the sidebar from my article on casting gives some
comparison figures for various types of calls compared to simple calculations
and an object allocation:
http://www.javaworld.com/javaworld/jw-12-1999/jw-12-performance.html#sidebar1

Object/array allocations are pretty much proportional to the size of the object,
but there's an overhead of about 20-30 bytes/object within the JVM. throw/catch
exception is *much* more expensive than any reasonably sized object allocation
(partially because the exception itself is probably a large object, with all the
stack trace information).

  - Dennis

Dennis M. Sosnoski
Sosnoski Software Solutions, Inc.
http://www.sosnoski.com

Robert Young wrote:
>
> the last appendix, or at least one of them, in Bruce Eckel's
> "Thinking in Java".  i didn't see it in the on line current copy.
> i don't have the book here, but it has relative timings for
> most operations.  new Array is actually more expensive than
> new Object.  the base, as i recall, is simple assignment.  and
> i don't recall whether it states which VM is described, nor
> what differences might exist among VM's.  new Object is
> about 3,000 and new Array is about 5,000; if memory
> serves.  the next most expensive was a few hundred.
>
> robert young
>
> On Wednesday, December 22, 1999 2:03 PM, Steven Owens [SMTP:[EMAIL PROTECTED]] wrote:
> > Craig McClanahan writes:
> >
> > > The answer, of course, is "it depends on your application."  A couple of things
> > > to think about: [...good info...]
> >
> >      Something I've been kind of wanting for a while is a relative
> > guide to how "expensive" various things are in java, like a method
> > call vs. a variable reference vs. instantiating an object vs. cloning
> > an object vs. etc.  Not so much absolute values as relative cost, just
> > to give me a guide for the general impact of such things.
> >
> >      Does anything like this exist?  I've read Dennis Sosnoski's
> > articles and there's something about this at
> > http://www.sosnoski.com/Java/Session/Specifics2.html, but is there
> > anything more comprehensive?
> >
> > Steven J. Owens
> > [EMAIL PROTECTED]
> > [EMAIL PROTECTED]
> >
> > ___________________________________________________________________________
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > Resources: http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
> >
> >
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to