Skip to content

Commit

Permalink
CLDR-17371 perf test for DTD insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
srl295 committed Feb 22, 2024
1 parent 6834f4c commit 34c7b2e
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static void read(
}
}

private static final XMLReader createXMLReader(
public static final XMLReader createXMLReader(
int handlers, boolean validating, AllHandler allHandler)
throws SAXNotRecognizedException, SAXNotSupportedException {
XMLReader xmlReader = createXMLReader(validating);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.unicode.cldr.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.unicode.cldr.util.XMLFileReader.LoggingHandler;
import org.unicode.cldr.util.XMLFileReader.SimpleHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class TestDTDInsertingReaderFactory {
private static final int COUNT = 10; // increase this for perf testing
private static final String COMMON_MT = "common/main/mt.xml";
private static final String KEYBOARDS_MT = "keyboards/3.0/mt.xml";

@Test
void TestProcessPathValues() {
for (int i = 0; i < COUNT; i++) {
XMLFileReader.processPathValues(COMMON_MT, true, new SimpleHandler());
}
}

@Test
void TestReadJar() throws IOException {
for (int i = 0; i < COUNT; i++) {
new XMLFileReader()
.setHandler(new XMLFileReader.SimpleHandler())
.readCLDRResource("dl_iso_table_a1.xml", -1, false);
}
}

@Test
void TestReadCommon() throws FileNotFoundException, IOException {
for (int i = 0; i < COUNT; i++) {
new XMLFileReader()
.setHandler(new XMLFileReader.SimpleHandler())
.read(COMMON_MT, -1, true);
}
}

@Test
void TestReadKeyboard() throws FileNotFoundException, IOException {
for (int i = 0; i < COUNT; i++) {
new XMLFileReader()
.setHandler(new XMLFileReader.SimpleHandler())
.read(KEYBOARDS_MT, -1, true);
}
}

@Test
void TestReadKeyboardByte() throws IOException, SAXException {
// verify that reading via InputStream (byte) works as well
try (InputStream fis = new FileInputStream(KEYBOARDS_MT); ) {
InputSource is = new InputSource(fis);
is.setSystemId(KEYBOARDS_MT);
is = DTDInsertingReaderFactory.wrap(is);
XMLFileReader.createXMLReader(-1, true, new LoggingHandler()).parse(is);
}
}

@Test
void TestReadKeyboardChar() throws IOException, SAXException {
// verify that reading via Reader (char) works as well
try (InputStream fis = new FileInputStream(KEYBOARDS_MT);
InputStreamReader isr = new InputStreamReader(fis); ) {
InputSource is = new InputSource(isr);
is.setSystemId(KEYBOARDS_MT);
is = DTDInsertingReaderFactory.wrap(is);
XMLFileReader.createXMLReader(-1, true, new LoggingHandler()).parse(is);
}
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
public void TestBytePerf(boolean wrapped) throws IOException, SAXException {
for (int i = 0; i < COUNT; i++) {
// mimic XMLFileHandler.read() here, but with wrapping enabled/disabled
try (InputStream fis = new FileInputStream(COMMON_MT); ) {
InputSource is = new InputSource(fis);
is.setSystemId(COMMON_MT);
if (wrapped) is = DTDInsertingReaderFactory.wrap(is);
XMLFileReader.createXMLReader(-1, true, new LoggingHandler()).parse(is);
}
}
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
public void TestCharPerf(boolean wrapped) throws IOException, SAXException {
for (int i = 0; i < COUNT; i++) {
// mimic XMLFileHandler.read() here, but with wrapping enabled/disabled
try (InputStream fis = new FileInputStream(COMMON_MT);
InputStreamReader isr = new InputStreamReader(fis); ) {
InputSource is = new InputSource(isr);
is.setSystemId(COMMON_MT);
if (wrapped) is = DTDInsertingReaderFactory.wrap(is);
XMLFileReader.createXMLReader(-1, true, new LoggingHandler()).parse(is);
}
}
}
}

0 comments on commit 34c7b2e

Please sign in to comment.