[jdom-interest] lookup for the parser

Kesav Kumar kesavk at voquette.com
Fri Mar 23 14:44:34 PST 2001


I don't really agree with the 0 miliisecods.  The class loading and lookup
all depends on the runtime of JDK how fast it loads a class from the class
path.  If you have somany paths on the classpath and your xerces happened to
be the last in all paths it is going to take some time to load the parser.
Once any class loads into memory once usually runtime keeps track of the
class for a while in that time if we request for the same class you are
luckky you will get class in 0 msecs.  But once you request for the class
after some time it may again take the same time which took for the initial
time.  This all depends on the runtime environment features Hotspot, JIT
kind of things may give good timing and others may give poor timing.  I just
wrote the following code to test the time and the following is the result
what i got



public class JDOMTest
{

	public static void main(String args[])
	{
		try
		{
			SAXBuilder builder = new SAXBuilder(false);
			for(int i=0; i<10; i++)
			{
				Document doc = builder.build(new
BufferedInputStream(new FileInputStream(args[0]), 1024));
				Thread.sleep(5000);
			}
		} catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
}

output is

Took: 1291 msec
Took: 40 msecs
Took: 40 msecs
Took: 40 msecs
Took: 0 msecs
Took: 0 msecs
Took: 160 msecs
Took: 10 msecs
Took: 10 msecs
Took: 0 msecs

It depends on the m/c also I am using WinNT 533MH JDK1.3 hotspot server.
This is when I use xerces as the parser if you use JAXP i guess time will be
more becaues we have method invocations also.





Kesav Kumar
Software Engineer
Voquette, Inc.
650 356 3740
mailto:kesavk at voquette.com
http://www.voquette.com
Voquette...Delivering Sound Information


-----Original Message-----
From: Jason Hunter [mailto:jhunter at collab.net]
Sent: Friday, March 23, 2001 1:31 PM
To: Kesav Kumar
Cc: jdom-interest at jdom.org
Subject: Re: [jdom-interest] lookup for the parser


I just timed how long it takes to execute the build() method up until to
the parse step.  The first time though takes a bit of time due to class
loading.  The second time through takes "0" milliseconds.  It's faster
than the resolution on the system clock.  Seems it's not expensive
enough to worry about.

-jh-

Kesav Kumar wrote:
> 
> Right now in SAXBuilder all the logic for lookup for the parser and
> instantiating the correct parser is in build method.  Usually people
create
> SAXBuilder instance once and try to parse as many documents as they want.
I
> feel we can skip this logic of looking up for parse and instantiating
parser
> can be skipped if we move the logic to constructor.  Right now when ever
we
> use build method all the logic gets executed which involves method
> invcoations through reflection which is an expensive.  We can reduce all
> these costs if we move the logic from build method to constructor of the
> SAXBuilder.  Making the parser(XMLReader object) static would reduce the
> parser lookup every time.
> 
> Kesav Kumar
> Software Engineer
> Voquette, Inc.
> 650 356 3740
> mailto:kesavk at voquette.com
> http://www.voquette.com
> Voquette...Delivering Sound Information
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com



More information about the jdom-interest mailing list