Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Re: Verifier.checkPCData

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: Wolfgang Hoschek <whoschek AT lbl.gov>
  • Cc: Elliotte Harold <elharo AT metalab.unc.edu>, xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Re: Verifier.checkPCData
  • Date: Mon, 20 Dec 2004 10:24:05 -0800

I think I must have made a copy&paste mistake. Actually, even for small text's there's not much difference as shown when rerunning again. Hence, the patch only shows significant benefits on VMs with strong optimizing compilers. On the other hand, it does not seem to hurt on poorly optimizing VMs.

NEW VERSION:
[hoschek /Users/hoschek/unix/devel/saxon-xq-tests/testsuite] fire-java gov.lbl.dsd.firefish.trash.XomPCDataBench 2 10000000
time[sec]=18.18
MB/sec=1.1001099925342726
checksum=0

OLD VERSION:
[hoschek /Users/hoschek/unix/devel/saxon-xq-tests/testsuite] fire-java gov.lbl.dsd.firefish.trash.XomPCDataBench 2 10000000
time[sec]=19.212
MB/sec=1.0410160374345465
checksum=0

Wolfgang.

On Dec 20, 2004, at 10:13 AM, Wolfgang Hoschek wrote:

Elliotte,

I tried my version of Verifier.checkPCData against your, using a little (somewhat flaky) micobenchmark. If I remember you said your version is better for poorly optimizing VMs such as the (latest stable) OSX 1.4.2 client VM. So I tried this using that OSX client VM, even though I usually run 1.5 server VM.

Results: For small texts (common case) my version is 10 times faster. For large texts performance is pretty much the same.

The main diff is not using toCharArray() plus a few minor diffs. I recommend removing similar toCharArray() also in other checkXYZ methods.

SMALL TEXTS (2 chars each)
---------------------
OLD VERSION:
[hoschek /Users/hoschek/unix/devel/saxon-xq-tests/testsuite] fire-java gov.lbl.dsd.firefish.trash.XomPCDataBench 2 10000000
time[sec]=19.693
MB/sec=1.0155892547693883
checksum=0


NEW VERSION:
[hoschek /Users/hoschek/unix/devel/saxon-xq-tests/testsuite] fire-java gov.lbl.dsd.firefish.trash.XomPCDataBench 2 10000000
time[sec]=1.943
MB/sec=10.293360999541997




SMALL TEXTS (2000 chars each)
-----------------------------
OLD VERSION:
[hoschek /Users/hoschek/unix/devel/saxon-xq-tests/testsuite] fire-java gov.lbl.dsd.firefish.trash.XomPCDataBench 2000 400000
time[sec]=33.291
MB/sec=24.03051849448083
checksum=0

NEW VERSION:
[hoschek /Users/hoschek/unix/devel/saxon-xq-tests/testsuite] fire-java gov.lbl.dsd.firefish.trash.XomPCDataBench 2000 400000
time[sec]=34.47
MB/sec=23.20858635535846
checksum=0

Below are the test driver and checkPCData

import nu.xom.*;

public class XomPCDataBench {

public static void main(String[] args) throws Exception {

int size = Integer.parseInt(args[0]);
int runs = Integer.parseInt(args[1]);

char[] chars = new char[size];
for (int i=0; i < size; i++) chars[i] = 'x';
String str = new String(chars);

int checksum = 0;

long start = System.currentTimeMillis();
for (int k=0; k < runs; k++) {
Text text = new Text(str);
checksum += text.getChildCount();
}

long end = System.currentTimeMillis();
System.out.println("time[sec]=" + (end-start)/1000.0f);
System.out.println("MB/sec=" + ((1.0 * runs * size / 1000000.0) / ((end-start)/1000.0f)));
System.out.println("checksum="+checksum);
}
}

static void checkPCDATA(String text) {
if (!checkPCDATA) return;
if (text == null)
throwIllegalCharacterDataException(text, "Null text");
// char[] data = text.toCharArray();
byte[] myFlags = flags; // cache static var
// try {
for (int i = 0, len = text.length(); i < len; i++) {
int result = text.charAt(i);
if (result < 0xD800 || result > 0xDBFF) {
// try {
if ((myFlags[result] & XML_CHARACTER)
== 0) {

throwIllegalCharacterDataException(text, "0x"
+
Integer.toHexString(result)
+ " is not allowed
in XML content");
}
// } catch (ArrayIndexOutOfBoundsException ex) {
// // moved out of inner loop
(myFlags[result])
// throwIllegalCharacterDataException(text,
"Bad Surrogate Pair");
//// IllegalCharacterDataException ide = new IllegalCharacterDataException(
//// "Bad Surrogate Pair",
ex);
//// ide.setData(text);
//// throw ide;
// }
} // end if
else {
i++; // increment past low surrogate
int low = (i < len ? text.charAt(i) :
0);
if (low < 0xDC00 || low > 0xDFFF) {

throwIllegalCharacterDataException(text,
"Bad surrogate
pair");
}
// result =
decodeSurrogatePair(result, data[i+1]);
// all properly matched surrogate
pairs are legal in PCDATA
}
}
// not needed anymore
// catch (IllegalCharacterDataException ex) {
// ex.setData(text);
// throw ex;
// }

}



// constants for the bit flags in the characters lookup table
private final static int XML_CHARACTER = 1;
private final static int NAME_CHARACTER = 2;
private final static int NAME_START_CHARACTER = 4;
private final static int NCNAME_CHARACTER = 8;
// use ints rather than byte for constants (bit operations must be implicitly propagated to ints anyway)



-----------------------------------------------------------------------
Wolfgang Hoschek | email: whoschek AT lbl.gov
Distributed Systems Department | phone: (415)-533-7610
Berkeley Laboratory | http://dsd.lbl.gov/~hoschek/
-----------------------------------------------------------------------






Archive powered by MHonArc 2.6.24.

Top of Page