Using Java 2.11 version. I'm building a xml binding component based on the CD Catalog data binding example. I have a fairly complex but rather small doc 2000 bytes about. And AutoPilot.bind() seems quite slow...
int count = 10000;
long start = System.nanoTime();
for(int i = 0; i <= count; i++)
{
//Init VTDGen, VTGNav here...
AutoPilot ap0 = new Autopilot();
AutoPilot ap1 = new Autopilot();
AutoPilot ap2 = new Autopilot();
AutoPilot ap3 = new Autopilot();
AutoPilot ap4 = new Autopilot();
// Set the XPAth for auto pilots here...
// Read bytes and parse...
// Bind autopilot to NAV.
MyObj mine = new MyObj();
// Do data binding here to My Object here...
}
long end = System.nanoTime();
long avgTime = (end - start) / count;
Hardware = 3GH 8 Core intel
Avg parse time is about 80000 nanoseconds.
Now if you Move the creation of Autopilot out of the loop, the average parse time is 10000 nano seconds.
Of course here this works because we are parsing the same document over and over. Now picture a server scenario like a servlet where each request parses what ever the received XML document is. It would be nice if we could reuse the auto pilot instead of creating a new one.
I remember reading somewhere to create a pool of autopilots but that's no fun especially where you have over a dozen autopilots.