Add timing tests

This commit is contained in:
James Agnew 2019-09-19 20:39:16 -04:00
parent c2c07c95fc
commit 6f6cc960ad
1 changed files with 132 additions and 0 deletions

View File

@ -2,9 +2,11 @@ package ca.uhn.fhir.parser;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.util.StopWatch;
import ca.uhn.fhir.util.TestUtil;
import com.google.common.collect.Sets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.NullWriter;
import org.apache.commons.lang.StringUtils;
import org.hl7.fhir.r4.model.*;
import org.junit.AfterClass;
@ -14,8 +16,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.core.IsNot.not;
@ -444,6 +448,134 @@ public class JsonParserR4Test {
}
/**
* 2019-09-19
* 18:24:48.548 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:483] - Encoded 200 passes - 50ms / pass - 19.7 / second
* 18:24:52.472 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:483] - Encoded 300 passes - 47ms / pass - 21.3 / second
* 18:24:56.428 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:483] - Encoded 400 passes - 45ms / pass - 22.2 / second
* 18:25:00.463 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:483] - Encoded 500 passes - 44ms / pass - 22.6 / second
*
*/
@Test
@Ignore
public void testTimingsOutput() throws IOException {
Bundle b = createBigBundle();
IParser parser = ourCtx.newJsonParser();
StopWatch sw = new StopWatch();
for (int i = 0; ; i++) {
parser.encodeResourceToWriter(b, new NullWriter());
if (i % 100 == 0) {
ourLog.info("Encoded {} passes - {} / pass - {} / second", i, sw.formatMillisPerOperation(i), sw.formatThroughput(i, TimeUnit.SECONDS));
}
}
}
/**
* 2019-09-19
* 18:33:08.720 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:495] - Encoded 200 passes - 47ms / pass - 21.2 / second
* 18:33:12.453 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:495] - Encoded 300 passes - 43ms / pass - 22.7 / second
* 18:33:16.195 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:495] - Encoded 400 passes - 42ms / pass - 23.6 / second
* 18:33:19.912 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:495] - Encoded 500 passes - 41ms / pass - 24.2 / second
*/
@Test
@Ignore
public void testTimingsOutputXml() throws IOException {
Bundle b = createBigBundle();
IParser parser = ourCtx.newXmlParser();
StopWatch sw = new StopWatch();
for (int i = 0; ; i++) {
parser.encodeResourceToWriter(b, new NullWriter());
if (i % 100 == 0) {
ourLog.info("Encoded {} passes - {} / pass - {} / second", i, sw.formatMillisPerOperation(i), sw.formatThroughput(i, TimeUnit.SECONDS));
}
}
}
/**
* 2019-09-19
* 18:31:01.513 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:486] - Parsed 600 passes - 37ms / pass - 27.0 / second
* 18:31:04.454 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:486] - Parsed 700 passes - 35ms / pass - 27.8 / second
* 18:31:07.451 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:486] - Parsed 800 passes - 35ms / pass - 28.4 / second
* 18:31:10.457 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:486] - Parsed 900 passes - 34ms / pass - 28.9 / second
*/
@Test
@Ignore
public void testTimingsInput() throws IOException {
Bundle b = createBigBundle();
IParser parser = ourCtx.newJsonParser();
String input = parser.encodeResourceToString(b);
StopWatch sw = new StopWatch();
for (int i = 0; ; i++) {
parser.parseResource(input);
if (i % 100 == 0) {
ourLog.info("Parsed {} passes - {} / pass - {} / second", i, sw.formatMillisPerOperation(i), sw.formatThroughput(i, TimeUnit.SECONDS));
}
}
}
/**
* 2019-09-19
* 18:32:04.518 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:513] - Parsed 200 passes - 37ms / pass - 26.8 / second
* 18:32:07.829 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:513] - Parsed 300 passes - 35ms / pass - 27.8 / second
* 18:32:11.087 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:513] - Parsed 400 passes - 35ms / pass - 28.5 / second
* 18:32:14.357 [main] INFO ca.uhn.fhir.parser.JsonParserR4Test [JsonParserR4Test.java:513] - Parsed 500 passes - 34ms / pass - 28.9 / second
*/
@Test
@Ignore
public void testTimingsInputXml() throws IOException {
Bundle b = createBigBundle();
IParser parser = ourCtx.newXmlParser();
String input = parser.encodeResourceToString(b);
StopWatch sw = new StopWatch();
for (int i = 0; ; i++) {
parser.parseResource(input);
if (i % 100 == 0) {
ourLog.info("Parsed {} passes - {} / pass - {} / second", i, sw.formatMillisPerOperation(i), sw.formatThroughput(i, TimeUnit.SECONDS));
}
}
}
private Bundle createBigBundle() {
Observation obs = new Observation();
Bundle b = new Bundle();
for (int i = 0; i < 100; i++) {
Patient pt = new Patient();
pt.addName().setFamily("FAM");
obs.getSubject().setResource(pt);
Encounter enc = new Encounter();
enc.setId("#1");
enc.setStatus(Encounter.EncounterStatus.ARRIVED);
obs.getEncounter().setReference("#1");
obs.getContained().add(enc);
obs.setEffective(new DateTimeType(new Date()));
obs.addIdentifier()
.setSystem("http://foo")
.setValue("blah");
obs.setValue(new Quantity().setSystem("UCUM").setCode("mg/L").setUnit("mg/L").setValue(123.567d));
b.addEntry().setResource(obs);
}
return b;
}
@AfterClass
public static void afterClassClearContext() {
TestUtil.clearAllStaticFieldsForUnitTest();