武HH
2017-07-25 23:37
@Test
public void testPerformance() throws Exception {
System.out.println("性能测试:");
//测试DOM的性能
long start = System.currentTimeMillis();
domXmlParser();
System.out.println("DOM:" + (System.currentTimeMillis() - start));
//测试SAX的性能
start = System.currentTimeMillis();
saxXmlParser();
System.out.println("SAX:" + (System.currentTimeMillis() - start));
//测试JDOM的性能
start = System.currentTimeMillis();
jdomXmlParser();
System.out.println("JDOM:" + (System.currentTimeMillis() - start));
//测试DOM4J的性能
start = System.currentTimeMillis();
dom4jXmlParser();
System.out.println("DOM4J:" + (System.currentTimeMillis() - start));
}上述的自定义的方法,测试结果如下:

idea生成测试类代码如下:
public class ParseTestTest {
@org.junit.Test
public void domXmlParser() throws Exception {
}
@org.junit.Test
public void saxXmlParser() throws Exception {
}
@org.junit.Test
public void jdomXmlParser() throws Exception {
}
@org.junit.Test
public void dom4jXmlParser() throws Exception {
}
}运行结果如下:

为什么idea生成的时间较短,而且除dom解析外其他解析没时间或几乎没时间呢
首先编译器不同,单位指标不同。还有一点,数据量太小了,不能说明所有问题
Java眼中的XML---文件读取
83199 学习 · 447 问题
相似问题