/*
* Copyright (c) 2000-2001 Sosnoski Software Solutions, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
package com.sosnoski.xmlbench;
import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
/**
* Benchmark program for comparing performance of Java XML parsers and
* document representations. Performance is measured in terms of both
* speed and memory requirement for constructing the document representation
* from a SAX parse, and in terms of speed for walking the representation and
* generating text output.
*
* @author Dennis M. Sosnoski
* @version 1.2
*/
public class XMLBench
{
/** Wait time between test documents (ms). */
public static final int DELAY_BETWEEN_DOCUMENTS = 400;
/** Output line length for brief format. */
public static final int BRIEF_LINE_LENGTH = 80;
/** Width of each item field in brief format. */
public static final int BRIEF_ITEM_WIDTH = 16;
/** Number of brief format items per output line. */
public static final int BRIEF_PER_LINE = BRIEF_LINE_LENGTH/BRIEF_ITEM_WIDTH;
/**
* Get test object. Constructs and returns an instance of the appropriate
* test class.
*
* @param name document model name to be tested
* @return document model test class instance (null if name not recognized)
*/
private static BenchBase getTestInstance(String name) {
if (name.equalsIgnoreCase("SAX")) {
return new BenchSAX();
} else if (name.equalsIgnoreCase("Crimson")) {
return new BenchCrimson();
} else if (name.equalsIgnoreCase("JDOM")) {
return new BenchJDOM();
} else if (name.equalsIgnoreCase("dom4j")) {
return new BenchDOM4J();
} else if (name.equalsIgnoreCase("Xerces")) {
return new BenchXercesBase();
} else if (name.equalsIgnoreCase("XercesD")) {
return new BenchXercesDeferred();
} else if (name.equalsIgnoreCase("Xerces2")) {
return new BenchXerces2Base();
} else if (name.equalsIgnoreCase("Xerces2D")) {
return new BenchXerces2Deferred();
} else if (name.equalsIgnoreCase("EXML")) {
return new BenchElectric();
} else if (name.equalsIgnoreCase("XPP")) {
return new BenchXPPBase();
} else if (name.equalsIgnoreCase("XPPp")) {
return new BenchXPPPull();
}
return null;
}
/**
* Read contents of file into byte array.
*
* @param file file to be read
* @return array of bytes containing all data from file
* @throws IOException on file access error
*/
private static byte[] getFileBytes(File file) throws IOException {
int length = (int)file.length();
byte[]data = new byte[length];
FileInputStream in = new FileInputStream(file);
int offset = 0;
do {
offset += in.read(data, offset, length-offset);
} while (offset < data.length);
return data;
}
/**
* Load data for file or directory argument. If the supplied path is a
* file, the returned array of arrays consists of a single byte array
* containing the date from that file. If the path is a directory, the
* returned array contains one value array for each file in the
* target directory.
*
* @param path file or directory path
* @return array of arrays of bytes containing all data from file(s)
* @throws IOException on file access error
*/
private static byte[][] getPathData(String path) throws IOException {
// check type of path supplied
File file = new File(path);
Vector data = new Vector();
if (file.isDirectory()) {
// get array of files in this directory
File[] files = file.listFiles();
byte[][] arrays = new byte[files.length][];
long[] stamps = new long[files.length];
// String[] names = new String[files.length];
int count = 0;
for (int i = 0; i < files.length; i++) {
if (files[i].isFile()) {
arrays[count] = getFileBytes(files[i]);
// names[count] = files[i].getName();
stamps[count++] = files[i].lastModified();
}
}
// (bubble) sort results by modify date of file
for (int i = 0; i < count; i++) {
for (int j = i+1; j < count; j++) {
if (stamps[j] < stamps[i]) {
long stamp = stamps[j];
stamps[j] = stamps[i];
stamps[i] = stamp;
byte[] array = arrays[j];
arrays[j] = arrays[i];
arrays[i] = array;
// String name = names[j];
// names[j] = names[i];
// names[i] = name;
}
}
// System.out.println(" sorted " + names[i]);
}
// convert results to sized array
byte[][] results = new byte[count][];
System.arraycopy(arrays, 0, results, 0, count);
return results;
} else {
byte[][] results = new byte[1][];
results[0] = getFileBytes(file);
return results;
}
}
/**
* Show test file results in brief format. This prints the results with
* multiple values per line, using the abbreviated value descriptions.
*
* @param values test result values (unreported values ignored)
* @param descripts value description texts
*/
private static void showBrief(int[] values, String[] descripts) {
StringBuffer line = new StringBuffer(BRIEF_LINE_LENGTH);
int position = 0;
for (int j = 0; j < values.length; j++) {
if (values[j] != Integer.MIN_VALUE) {
if (position == 0) {
if (j > 0) {
System.out.println(line);
line.setLength(0);
}
} else {
int end = position*BRIEF_ITEM_WIDTH;
while (line.length() < end) {
line.append(' ');
}
}
line.append(' ');
line.append(descripts[j]);
line.append('=');
line.append(values[j]);
position = (position+1) % BRIEF_PER_LINE;
}
}
System.out.println(line);
}
/**
* Show test file results in full format. This prints the results with
* a single value per line, using the detailed value descriptions.
*
* @param values test result values (unreported values ignored)
* @param descripts value description texts
*/
private static void showFull(int[] values, String[] descripts) {
for (int j = 0; j < values.length; j++) {
if (values[j] != Integer.MIN_VALUE) {
System.out.println(' ' + descripts[j] + " = " + values[j]);
}
}
}
/**
* Build text for showing results in compressed format. This uses an
* abbreviated value description followed by the corresponding result
* values for all test files in sequence, with comma separators.
*
* @param values array of test result value arrays
* @param descripts value description texts
* @param line buffer for output text accumulation
*/
private static void buildCompressed(int[][] values, String[] descripts,
StringBuffer line) {
int fcnt = values.length;
int vcnt = values[0].length;
for (int i = 0; i < vcnt; i++) {
line.append(',');
line.append(descripts[i]);
for (int j = 0; j < fcnt; j++) {
line.append(',');
if (values[j][i] != Integer.MIN_VALUE) {
line.append(values[j][i]);
}
}
}
}
/**
* Test driver, just reads the input parameters and executes the test.
*
* @param argv command line arguments
*/
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
java解析xml文档的性能测试 (265个子文件)
XMLBench.class 7KB
BenchBase.class 5KB
BenchDocBase.class 5KB
BenchSAX.class 3KB
BenchDOM4J.class 3KB
BenchXPP.class 3KB
BenchJDOM.class 3KB
BenchElectric.class 2KB
BenchDOM.class 2KB
BenchXerces2.class 2KB
BenchXerces.class 2KB
BenchXPPBase.class 1KB
BenchSAX$InnerHandler.class 1KB
BenchCrimson.class 1KB
BenchXPPPull.class 1KB
DocumentSummary.class 1KB
BenchXerces2Deferred.class 221B
BenchXercesDeferred.class 218B
BenchXerces2Base.class 216B
BenchXercesBase.class 213B
stylesheet.css 1KB
BenchBase.html 42KB
results.html 24KB
BenchDocBase.html 23KB
BenchXPP.html 23KB
BenchDOM4J.html 22KB
BenchJDOM.html 22KB
BenchElectric.html 21KB
BenchXerces2.html 20KB
BenchXerces.html 20KB
BenchDOM.html 19KB
BenchXPPBase.html 19KB
BenchCrimson.html 18KB
BenchXPPPull.html 17KB
BenchSAX.html 17KB
BenchXerces2Deferred.html 16KB
BenchXercesDeferred.html 16KB
BenchXerces2Base.html 16KB
BenchXercesBase.html 16KB
DocumentSummary.html 14KB
BenchSAX.InnerHandler.html 14KB
models.html 13KB
XMLBench.html 10KB
package-summary.html 7KB
conclusions.html 4KB
tests.html 4KB
index.html 3KB
documents.html 3KB
serialized-form.html 3KB
deprecated-list.html 3KB
download.html 3KB
allclasses-frame.html 2KB
package-frame.html 2KB
index.html 709B
packages.html 703B
xerces.jar 1.73MB
xercesImpl.jar 1.65MB
dom4j.jar 435KB
crimson.jar 200KB
xmlParserAPIs.jar 129KB
jdom.jar 104KB
XPP.jar 103KB
EXML.jar 46KB
sax2.jar 28KB
jaxp.jar 28KB
xmlbm.jar 27KB
sax2-ext.jar 994B
XMLBench.java 17KB
BenchDocBase.java 15KB
BenchBase.java 13KB
BenchSAX.java 9KB
BenchXPP.java 7KB
BenchJDOM.java 7KB
BenchDOM4J.java 7KB
BenchElectric.java 6KB
BenchDOM.java 6KB
DocumentSummary.java 5KB
BenchXerces2.java 4KB
BenchXerces.java 4KB
BenchCrimson.java 3KB
BenchXPPBase.java 3KB
BenchXPPPull.java 3KB
BenchXerces2Deferred.java 2KB
BenchXercesDeferred.java 2KB
BenchXerces2Base.java 2KB
BenchXercesBase.java 2KB
MANIFEST.MF 45B
package-list 22B
mem-mid.png 8KB
large-times.png 8KB
bld-times-mid.png 8KB
bld-times-small.png 8KB
bldwalk-times-mid.png 7KB
bldwalk-times-small.png 7KB
mem-small.png 7KB
mod-times-mid.png 7KB
write-times-mid.png 7KB
walk-times-mid.png 6KB
write-times-small.png 6KB
mem-large.png 6KB
共 265 条
- 1
- 2
- 3
资源评论
- girl_20082015-05-20比较实用,能够处理常见的xml文件解析
cybaiu
- 粉丝: 1
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 技术面试最后反问面试官的话 校招面试非技术问题有哪些 非技术问题如何回答.png
- NB-IOT-BC26全网通模块Altium+ CADENCE +PADS三种格式(原理图SCH+PCB封装库)文件.zip
- 基于微信小程序开发的校园失物招领系统源码毕业设计(优质项目源码).zip
- 词向量是一种将自然语言中的单词转换为数值向量的技术,它能够捕捉词义和上下文信息
- nmap与masscan的简单使用
- MyBatis动态SQL.pdf
- 基于stm32单片机protues仿真的温湿度控制系统设计(仿真图、源代码)
- 词向量:自然语言处理的基石
- mybatis动态sql
- 40G微信小程序开发教程(工具插件+视频教程)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功