Skip to content

Commit 8dfa126

Browse files
committed
issue #424 - refactor parser benchmark and add valueset benchmarks
1. introduced run options under FHIRBenchmarkRunner for setting JMH params instead of passing via system properties 2. refactored FHIRParserBenchmark to use JMH params 3. introduced LargeValueSetCreator under fhir-examples-generator and specific examples for json and xml 4. added FHIRValueSetBenchmarks for measuring ValueSet parse times 5. added LargeValueSetCreator variants for creating HashSet and text file equivalents, and added Benchmarks for measuring parse times for those as well Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
1 parent 3f15fdf commit 8dfa126

19 files changed

Lines changed: 100341 additions & 241 deletions

File tree

fhir-benchmark/src/main/java/com/ibm/fhir/benchmark/FHIRGeneratorBenchmark.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66

77
package com.ibm.fhir.benchmark;
88

9-
import static com.ibm.fhir.benchmark.runner.FHIRBenchmarkRunner.PROPERTY_EXAMPLE_NAME;
10-
119
import java.io.StringReader;
1210
import java.io.Writer;
1311

1412
import org.hl7.fhir.instance.model.api.IBaseResource;
1513
import org.openjdk.jmh.annotations.Benchmark;
14+
import org.openjdk.jmh.annotations.Param;
1615
import org.openjdk.jmh.annotations.Scope;
1716
import org.openjdk.jmh.annotations.Setup;
1817
import org.openjdk.jmh.annotations.State;
@@ -30,9 +29,6 @@ public class FHIRGeneratorBenchmark {
3029
@State(Scope.Benchmark)
3130
public static class FHIRGeneratorState {
3231
public static final Writer NOP_WRITER = BenchmarkUtil.createNOPWriter();
33-
public static final String SPEC_EXAMPLE_NAME = System.getProperty(PROPERTY_EXAMPLE_NAME);
34-
public static final String JSON_SPEC_EXAMPLE = BenchmarkUtil.getSpecExample(Format.JSON, SPEC_EXAMPLE_NAME);
35-
public static final String XML_SPEC_EXAMPLE = BenchmarkUtil.getSpecExample(Format.XML, SPEC_EXAMPLE_NAME);
3632

3733
public FhirContext context;
3834
public FHIRGenerator jsonGenerator;
@@ -48,6 +44,12 @@ public void setUp() throws Exception {
4844
resource = FHIRParser.parser(Format.JSON).parse(new StringReader(JSON_SPEC_EXAMPLE));
4945
baseResource = context.newJsonParser().parseResource(new StringReader(JSON_SPEC_EXAMPLE));
5046
}
47+
48+
@Param({"test"})
49+
public String JSON_SPEC_EXAMPLE;
50+
51+
@Param({"test"})
52+
public String XML_SPEC_EXAMPLE;
5153
}
5254

5355
@Benchmark
@@ -72,7 +74,6 @@ public void benchmarkHAPIXMLGenerator(FHIRGeneratorState state) throws Exception
7274

7375
public static void main(String[] args) throws Exception {
7476
new FHIRBenchmarkRunner(FHIRGeneratorBenchmark.class)
75-
.property(PROPERTY_EXAMPLE_NAME, BenchmarkUtil.getRandomSpecExampleName())
76-
.run();
77+
.run(BenchmarkUtil.getRandomSpecExampleName());
7778
}
7879
}

fhir-benchmark/src/main/java/com/ibm/fhir/benchmark/FHIRParserBenchmark.java

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66

77
package com.ibm.fhir.benchmark;
88

9-
import static com.ibm.fhir.benchmark.runner.FHIRBenchmarkRunner.PROPERTY_EXAMPLE_NAME;
10-
9+
import java.io.IOException;
1110
import java.io.StringReader;
12-
import java.io.Writer;
1311

1412
import org.openjdk.jmh.annotations.Benchmark;
13+
import org.openjdk.jmh.annotations.Param;
1514
import org.openjdk.jmh.annotations.Scope;
1615
import org.openjdk.jmh.annotations.Setup;
1716
import org.openjdk.jmh.annotations.State;
@@ -20,54 +19,65 @@
2019
import com.ibm.fhir.benchmark.util.BenchmarkUtil;
2120
import com.ibm.fhir.model.format.Format;
2221
import com.ibm.fhir.model.parser.FHIRParser;
22+
import com.ibm.fhir.model.resource.Resource;
2323

2424
import ca.uhn.fhir.context.FhirContext;
2525
import ca.uhn.fhir.parser.StrictErrorHandler;
2626

27+
2728
public class FHIRParserBenchmark {
29+
@State(Scope.Thread)
30+
public static class FHIRParsers {
31+
public FHIRParser jsonParser = FHIRParser.parser(Format.JSON);
32+
public FHIRParser xmlParser = FHIRParser.parser(Format.XML);
33+
}
34+
2835
@State(Scope.Benchmark)
2936
public static class FHIRParserState {
30-
public static final Writer NOP_WRITER = BenchmarkUtil.createNOPWriter();
31-
public static final String SPEC_EXAMPLE_NAME = System.getProperty(PROPERTY_EXAMPLE_NAME);
32-
public static final String JSON_SPEC_EXAMPLE = BenchmarkUtil.getSpecExample(Format.JSON, SPEC_EXAMPLE_NAME);
33-
public static final String XML_SPEC_EXAMPLE = BenchmarkUtil.getSpecExample(Format.XML, SPEC_EXAMPLE_NAME);
34-
3537
public FhirContext context;
36-
public FHIRParser jsonParser;
37-
public FHIRParser xmlParser;
38+
public String JSON_SPEC_EXAMPLE;
39+
public String XML_SPEC_EXAMPLE;
40+
41+
// JMH will inject the value into the annotated field before any Setup method is called.
42+
@Param({"valuesets"})
43+
public String exampleName;
3844

3945
@Setup
40-
public void setUp() {
46+
public void setUp() throws IOException {
47+
if (exampleName == null) {
48+
System.err.println("exampleName is null; if you're in Eclipse then make sure annotation processing is on and you've ran 'mvn clean package'.");
49+
System.exit(1);
50+
}
51+
System.out.println("Setting up for example " + exampleName);
4152
context = FhirContext.forR4();
4253
context.setParserErrorHandler(new StrictErrorHandler());
43-
jsonParser = FHIRParser.parser(Format.JSON);
44-
xmlParser = FHIRParser.parser(Format.XML);
54+
JSON_SPEC_EXAMPLE = BenchmarkUtil.getSpecExample(Format.JSON, exampleName);
55+
XML_SPEC_EXAMPLE = BenchmarkUtil.getSpecExample(Format.XML, exampleName);
4556
}
4657
}
4758

4859
@Benchmark
49-
public void benchmarkJsonParser(FHIRParserState state) throws Exception {
50-
state.jsonParser.parse(new StringReader(FHIRParserState.JSON_SPEC_EXAMPLE));
60+
public Resource benchmarkJsonParser(FHIRParsers parsers, FHIRParserState state) throws Exception {
61+
return parsers.jsonParser.parse(new StringReader(state.JSON_SPEC_EXAMPLE));
5162
}
5263

5364
@Benchmark
54-
public void benchmarkXMLParser(FHIRParserState state) throws Exception {
55-
state.xmlParser.parse(new StringReader(FHIRParserState.XML_SPEC_EXAMPLE));
65+
public Resource benchmarkXMLParser(FHIRParsers parsers, FHIRParserState state) throws Exception {
66+
return parsers.xmlParser.parse(new StringReader(state.XML_SPEC_EXAMPLE));
5667
}
5768

5869
@Benchmark
5970
public void benchmarkHAPIJsonParser(FHIRParserState state) throws Exception {
60-
state.context.newJsonParser().parseResource(new StringReader(FHIRParserState.JSON_SPEC_EXAMPLE));
71+
state.context.newJsonParser().parseResource(new StringReader(state.JSON_SPEC_EXAMPLE));
6172
}
6273

6374
@Benchmark
6475
public void benchmarkHAPIXMLParser(FHIRParserState state) throws Exception {
65-
state.context.newXmlParser().parseResource(new StringReader(FHIRParserState.XML_SPEC_EXAMPLE));
76+
state.context.newXmlParser().parseResource(new StringReader(state.XML_SPEC_EXAMPLE));
6677
}
6778

6879
public static void main(String[] args) throws Exception {
69-
new FHIRBenchmarkRunner(FHIRParserBenchmark.class)
70-
.property(PROPERTY_EXAMPLE_NAME, BenchmarkUtil.getRandomSpecExampleName())
71-
.run();
80+
// new FHIRBenchmarkRunner(FHIRParserBenchmark.class).runAll();
81+
new FHIRBenchmarkRunner(FHIRParserBenchmark.class).run();
7282
}
7383
}

fhir-benchmark/src/main/java/com/ibm/fhir/benchmark/FHIRParserValidatorGeneratorBenchmark.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public void benchmarkHAPIXMLParserValidatorGenerator(FHIRParserValidatorGenerato
9191

9292
public static void main(String[] args) throws Exception {
9393
new FHIRBenchmarkRunner(FHIRParserValidatorGeneratorBenchmark.class)
94-
.property(PROPERTY_EXAMPLE_NAME, BenchmarkUtil.getRandomSpecExampleName())
9594
.run();
9695
}
9796
}

fhir-benchmark/src/main/java/com/ibm/fhir/benchmark/FHIRPathEvaluatorBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ public static void main(String[] args) throws Exception {
9191
new FHIRBenchmarkRunner(FHIRPathEvaluatorBenchmark.class)
9292
.property(PROPERTY_EXAMPLE_NAME, EXAMPLE_NAME)
9393
.property(PROPERTY_EXPRESSION, EXPRESSION)
94-
.run();
94+
.run(BenchmarkUtil.getRandomSpecExampleName());
9595
}
9696
}

fhir-benchmark/src/main/java/com/ibm/fhir/benchmark/FHIRValidatorBenchmark.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public void benchmarkHAPIValidator(FHIRValidatorState state) throws Exception {
6363

6464
public static void main(String[] args) throws Exception {
6565
new FHIRBenchmarkRunner(FHIRValidatorBenchmark.class)
66-
.property(PROPERTY_EXAMPLE_NAME, BenchmarkUtil.getRandomSpecExampleName())
67-
.run();
66+
.run(BenchmarkUtil.getRandomSpecExampleName());
6867
}
6968
}

fhir-benchmark/src/main/java/com/ibm/fhir/benchmark/FHIRValueSetBenchmark.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

fhir-benchmark/src/main/java/com/ibm/fhir/benchmark/FHIRValueSetBenchmark2.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

fhir-benchmark/src/main/java/com/ibm/fhir/benchmark/FHIRValueSetBenchmark3.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)