[jdom-interest] NoSuch*Exceptions in JDOM

Petri Wessman orava at termiitti.akumiitti.fi
Mon Jul 10 08:05:15 PDT 2000


On Mon, 10 Jul 2000 08:38:44 -0500, Brett McLaughlin <brett.mclaughlin at lutris.com> said:

>> Beside the "is it good design" argument, you should take into account
>> the fact that throwing and catching exceptions carries a heavy
>> performance penalty in Java. There is a good, practical reason for

Brett> Where is your documentation for this? I don't believe that this is
Brett> accurate, but I'm willing to be proved wrong. Could you post docs or a
Brett> URL?

Well, I don't have any handy right now, it's a point that has come up
in various JavaWorld articles on Java performance, and I remember at
least two speakers at last year's Java One commenting on it.

I did a quick test just now on my Linux workstation. This is *NOT* a
benchmark or anything, I just wrote a loop that iterates 1M * 2 times
through a method call that returns a StringBuffer-built string based
on a parameter (not a constant, to avoid JVM optimization
triggering). First it does the method calls with direct value returns
(no exceptions throws), in the second pass it throws an exception
every time.

Results (averages of multiple runs):

JVM			no exceptions	exceptions

Blackdown 1.2.2.RC2	16s		38s
IBM 1.3 preview		 3s		18s
Sun 1.2.2		26s		34s

So it depends a bit on the JVM. The JIT compilers are hit quite
heavily, with exception throwing slowing things down dramatically. The
Sun non-JIT JVM doesn't show that much of a difference, but is still a
bit slower with exceptions.

I'll try to run a test with JDOM vs a hacked JDOM as soon as I have
time. I'll also try to dig up something on the Web concerning the
subject.

Bottom line: what I said is based on what I've heard from numerous
reputable sources, and my quick-n-dirty test results seem to bear out
the conclusion that exceptions can cause slowdown. On the other hand,
I don't have "hard" evidence on the subject (literature, URLs).

//Petri



More information about the jdom-interest mailing list