Add parser stress test
This commit is contained in:
parent
1720144cfb
commit
b30de00ea1
|
@ -0,0 +1,54 @@
|
|||
package ca.uhn.fhir.jpa.stresstest;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.test.BaseTest;
|
||||
import ca.uhn.fhir.util.StopWatch;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class StressTestParserTest extends BaseTest {
|
||||
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(StressTestParserTest.class);
|
||||
|
||||
@Test
|
||||
public void test() throws IOException {
|
||||
FhirContext ctx = FhirContext.forR4();
|
||||
String input = loadResource("/org/hl7/fhir/r4/model/valueset/valuesets.xml");
|
||||
|
||||
String json = ctx.newJsonParser().encodeResourceToString(ctx.newXmlParser().parseResource(input));
|
||||
|
||||
StopWatch sw = null;
|
||||
int loops = 100;
|
||||
|
||||
for (int i = 0; i < loops; i++) {
|
||||
ctx.newXmlParser().parseResource(input);
|
||||
if (i < 50) {
|
||||
ourLog.info("Parsed XML {} times", i);
|
||||
continue;
|
||||
} else if (i == 50) {
|
||||
sw = new StopWatch();
|
||||
continue;
|
||||
}
|
||||
ourLog.info("Parsed XML {} times - {}ms/pass", i, sw.getMillisPerOperation(i - 50));
|
||||
}
|
||||
|
||||
for (int i = 0; i < loops; i++) {
|
||||
Bundle parsed = (Bundle) ctx.newJsonParser().parseResource(json);
|
||||
if (i < 50) {
|
||||
ourLog.info("Parsed JSON with {} entries {} times", parsed.getEntry().size(), i);
|
||||
continue;
|
||||
} else if (i == 50) {
|
||||
sw = new StopWatch();
|
||||
continue;
|
||||
}
|
||||
ourLog.info("Parsed JSON {} times - {}ms/pass", i, sw.getMillisPerOperation(i - 50));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue