-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLDR-17371 perf test for DTD insertion
- Loading branch information
Showing
2 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
tools/cldr-code/src/test/java/org/unicode/cldr/util/TestDTDInsertingReaderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |