[XOM-interest] XOMTestCase.assertEquals() too slow

Wolfgang Hoschek wolfgang.hoschek at mac.com
Thu Jan 25 23:24:48 EST 2007

I have a test driver that runs tens of thousands of XML files from a  
test suite through XOMTestCase.assertEquals(Document, Document),  
among other functions. It works correctly, but takes hours to  
complete, so I thought I'd take a quick peek. For example, it turns  
out that, when running the simple non-namespaced 8 MB document  
downloadable at http://dsd.lbl.gov/~hoschek/tmp/largeemp.xml.tar.gz  
through the example code below, it takes only a split second to parse  
the document, but about 2 minutes to complete assertEquals(). While  
I'm normally more worried about the clarity than the performance of  
test case code, things are clearly getting a bit out of hands here.  
It's not clear why XOMTestCase.assertEquals() should be orders of  
magnitude slower than parsing or serialization. All of these should  
clearly be O(N) overall. Any significant improvement would be  
appreciated. The tests don't have to be blazing fast, just bearable.

import java.io.File;

import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.tests.XOMTestCase;

public class AssertEqualsTest {	
	public static void main(String[] args) throws Exception {
		long duration = 0;
		Builder builder = new Builder();
		for (int i=0; i < args.length; i++) {
			Document doc1 = builder.build(new File(args[i]));
			Document doc2 = new Document(doc1);
			long start = System.currentTimeMillis();

			XOMTestCase.assertEquals(doc1, doc2);

			long end = System.currentTimeMillis();
			duration = duration + (end - start);

		System.out.println("secs = " + (duration / 1000.0f));

More information about the XOM-interest mailing list