[jdom-interest] NoSuch*Exceptions in JDOM
orava at termiitti.akumiitti.fi
Mon Jul 10 09:45:11 PDT 2000
On Mon, 10 Jul 2000 11:25:47 -0500, philip.nelson at omniresources.com said:
philip> A typical result with 1,000,000 accesses of an exisiting element was
philip> something like this
philip> Time (ms) without exception: 3616
philip> Time (ms) with exception: 3605
philip> In reverse order....
philip> Time (ms) with exception: 3735
philip> Time (ms) without exception: 3715
philip> In reverse order again....
philip> Time (ms) without exception: 3676
philip> Time (ms) with exception: 3665
philip> I can't explain why the first call was a little slower whether
philip> or not an exception was used. The code is very simple so
philip> maybe someone else could explain it. Barring some obvious
philip> problem with that, it would seem that on my computer (Win NT
philip> WS 4.0 Sun JDK 1.2.2) there is not a dramatic difference with
philip> or without exceptions. I did see a somewhat greater
philip> difference running in my IDE but I was running with JUnit so I
philip> don't completely trust the results.
I see the problem in your test case: you're testing for a child which
exists in the XML. In this case the difference between the methods is
non-existent (as your test proves).
Declaring that something throws exceptions is not expensive. Actually
throwing the exceptions is.
Try running your code with the lines
Element test = form.getOptionalChild("field");
changed to something line
Element test = form.getOptionalChild("nosuchelement");
I think you'll see quite dramatic differences.
More information about the jdom-interest