[jdom-interest] NoSuch*Exceptions in JDOM

philip.nelson at omniresources.com philip.nelson at omniresources.com
Mon Jul 10 09:25:47 PDT 2000

> 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 threw together a test case based on JDOM with two methods added (since
we're talking primarily about optional elements, I used that name)

	public Element getOptionalChild(String name)  {
		return getOptionalChild(name, "");
	public Element getOptionalChild(String name, String uri)

		Iterator i = content.iterator();
		while (i.hasNext()) {
			Object obj = i.next();
			if (obj instanceof Element) {
				Element element = (Element)obj;
				if ((element.getNamespaceURI().equals(uri))
					(element.getName().equals(name))) {
					return element;

		// If we got here, none found
		return null;

A typical result with 1,000,000 accesses of an exisiting element was
something like this
Time (ms) without exception: 3616
Time (ms) with exception: 3605
In reverse order....
Time (ms) with exception: 3735
Time (ms) without exception: 3715
In reverse order again....
Time (ms) without exception: 3676
Time (ms) with exception: 3665

I can't explain why the first call was a little slower whether or not an
exception was used.  The code is very simple so maybe someone else could
explain it.  Barring some obvious problem with that, it would seem that on
my computer (Win NT WS 4.0 Sun JDK 1.2.2) there is not a dramatic difference
with or without exceptions.  I did see a somewhat greater difference running
in my IDE but I was running with JUnit so I don't completely trust the

I have attached the code I used for these tests 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestCase_Performance.java
Type: application/octet-stream
Size: 2508 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20000710/369805b4/TestCase_Performance.obj

More information about the jdom-interest mailing list