XSLT is Way Faster Using Java 5
By
February 6, 2005
BEA recently released a new version of JRockit, their super-fast server-side Java Virtual Machine (JVM). This new version offers J2SE 5 compatibility and (as usual) promises speed improvements over Sun's own JVM.
As my current project involves lots of XSLT, I ran some XSLT transformations through the new version of JRockit and compared the results with a couple of other JDKs. The benchmark I used runs a tiny XSL transformation 1000 times. It was run using a 3Ghz PC with 1GB RAM, running Win2K.
Here's a zip file containing the files I used to run the benchmark. I used JDOM 1.0 as it's a nice simple API. No doubt the benchmark code is sub-optimal, and no special VM params were used, just out of the box settings. Also I just ran it inside Eclipse 3.x, as the UI makes it pretty simple to change the launch JRE for an app.
Here's the Java "micro-benchmark" code (the XSLT and XML files can be found in the zip file):
1 package playpen;
2
3 import java.io.File;
4 import java.util.Iterator;
5
6 import org.jdom.Document;
7 import org.jdom.Element;
8 import org.jdom.input.SAXBuilder;
9 import org.jdom.output.XMLOutputter;
10 import org.jdom.transform.*;
11
12 public class Runner {
13
14 public static void main(String[] args) throws Exception{
15
16 File test=new File("F:/eclipse/workspace/xslt/playpen/test.xml");
17 SAXBuilder builder = new SAXBuilder();
18 Document doc = builder.build(test);
19
20 File style=new File("F:/eclipse/workspace/xslt/playpen/test1.xslt");
21 XSLTransformer trans=new XSLTransformer(style);
22 Document outdoc=null;
23
24 long ti=System.currentTimeMillis();
25 for (int x=0;x<1000;x++)
26 {
27 outdoc=trans.transform(doc);
28 }
29 System.out.println(System.currentTimeMillis()-ti);
30 }
31 }
The results were surprising to say the least:
| JVM |
Time to run (ms) |
x faster than Sun JDK 1.4.2 |
| Sun JDK 1.4.2 |
3700 |
|
| JRockit 8.1 (1.4.2) |
1600 |
2.31 |
| Sun JDK 5.0 (1.5.0_01) |
650 |
5.59 |
| JRockit 5 (1.5.0) |
540 |
7.88 |
So, JRockit still seems to be faster than Sun's equivalent JDK, but the MASSIVE speedup from 1.4.2 demonstrates that JDK 5.0/1.5/whatever is a lot faster with XSLT transformations.
I found these results intriguing (and encouraging!). It didn't take much investigation to discover the cause of the dramatic speedup: this page on Sun's website (JAXP 1.5.0 Release Notes) gives a pretty major clue. It looks as if they now use XSLTC, not Xalan as before. That's why it's so much faster. And as for straight XML, they now use Xerces, not Crimson.
As they've swapped over to a completely different implementation, there are bound to be some compatibility issues. Hopefully these will be minor though; and the inconvenience should be worth it, as the improvement is so dramatic. (There are also improvements in other areas besides performance; e.g. a built-in validation processor for XML Schema; ability to use alternative schema validators; Java-centric XPath APIs; and so on - see the above-linked compatibility guide for the full list).
These results should be good news for those doing XSLT not knowing that JDK 1.5 offers amazing speedups, even if you still use the Sun JDK - although JRockit still seems to be king, and is free too.
About the author:
Dino Fancellu is the Lead Technologist at , a UK-based Java consultancy firm. He has worked with Java since it was in Beta, and has been a commercial programmer since 1986, specialising in complex enterprise/financial systems.
Talkback - Have Your Say:
Post a new message
The Messages: No messages have been posted yet.
Post a new message
<< Back to Programming
<< Back to the Front Page
|