Tuesday
26
Feb 2008

XML Benchmarks - Allocation hurts

(11:40 am) Tags: [Software, Projects, D Programming Language]

I added Java DOM to the graphs. Building a tree in memory is not the fastest way to parse a doc, but it is the easiest way to modify the doc after parsing. Java 6 DOM shows off not too terribly bad in the parsing speed, but with all the allocation going on, RAM usage skyrockets, and the efficiency graph shows the pain.

This goes to show you how good library design and the D Programming Language come together to kick serious butt.

Popularity: 9%

Comments: (0)

XML Benchmarks - Java 6 DOM

(11:29 am) Tags: [Software, Projects]

I have added a Java 6 DOM to the benchmark, so I could compare the Tango DOM. I used Dom.java, listed here:

import java.io.*;
import javax.xml.parsers.*;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import java.io.IOException;

public class Dom {

public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
long length = file.length();

byte[] bytes = new byte[(int)length];

int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}

if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}

is.close();
return bytes;
}

public static void main(String[] args) {

if (args.length <= 0) {
System.out.println("Usage: java Dom filename");
return;
}
try {
String document = args[0];
int iterations = 2000;
byte[] content = getBytesFromFile(new File(document));
ByteArrayInputStream bais = new ByteArrayInputStream(content);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
for (int i = 0; i < 10; i++) {
long start = System.currentTimeMillis();
for (int j = 0; j < iterations; j++) {
parser.parse(new InputSource(bais));
bais.reset();
}
long stop = System.currentTimeMillis();
double timer = (stop - start) / 1000.0;
double total = (content.length * iterations) / (timer * (1024 * 1024));
System.out.print(total);
System.out.println(" MB/s");
}
}
catch (Exception e) {
e.printStackTrace();
}

}

}

Results on the quad core machine:

stonecobra@jeff-home:~/xmlbench$ java Dom hamlet.xml
47.97158513186668 MB/s
49.42985018499479 MB/s
49.71088484444904 MB/s
49.943635499212824 MB/s
49.86891851295874 MB/s
49.83630008373143 MB/s
49.93895912884773 MB/s
49.845615280008765 MB/s
49.845615280008765 MB/s
49.86891851295874 MB/s
stonecobra@jeff-home:~/xmlbench$ java Dom soap_mid.xml
28.16242814247465 MB/s
29.23571100413446 MB/s
29.16914517762231 MB/s
29.272451872527633 MB/s
29.295880544275597 MB/s
29.19240870915283 MB/s
29.3428505772142 MB/s
29.491456174060122 MB/s
29.54246180563062 MB/s
29.45755015408535 MB/s

Hamlet average: 49.63
Soap_mid average: 29.22

Popularity: 8%

Comments: (0)