Skip to content

Commit 3a080ef

Browse files
gitgabrioGabriele-Cardosi
andauthored
[incubator-kie-issues#1301] Create DMN benchmarks specifically targeting the codegen execution. (#288)
* [incubator-kie-issues#1301] Create codegen-specific benchmark * [incubator-kie-issues#1301] Add new codegen benchmark. Refactoring for inheritance --------- Co-authored-by: Gabriele-Cardosi <gabriele.cardosi@ibm.com>
1 parent 076b7a6 commit 3a080ef

File tree

6 files changed

+1318
-0
lines changed

6 files changed

+1318
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.drools.benchmarks.dmn.codegen;
21+
22+
import org.kie.dmn.api.core.DMNCompiler;
23+
import org.kie.dmn.api.core.DMNCompilerConfiguration;
24+
import org.kie.dmn.api.core.DMNContext;
25+
import org.kie.dmn.api.core.DMNModel;
26+
import org.kie.dmn.api.core.DMNRuntime;
27+
import org.kie.dmn.core.compiler.DMNCompilerConfigurationImpl;
28+
import org.kie.dmn.core.compiler.DMNCompilerImpl;
29+
import org.kie.dmn.core.compiler.RuntimeTypeCheckOption;
30+
import org.kie.dmn.core.impl.DMNRuntimeImpl;
31+
import org.kie.dmn.core.internal.utils.DMNRuntimeBuilder;
32+
import org.kie.dmn.feel.parser.feel11.profiles.DoCompileFEELProfile;
33+
import org.kie.dmn.feel.util.Either;
34+
import org.openjdk.jmh.annotations.Benchmark;
35+
import org.openjdk.jmh.annotations.BenchmarkMode;
36+
import org.openjdk.jmh.annotations.Measurement;
37+
import org.openjdk.jmh.annotations.Mode;
38+
import org.openjdk.jmh.annotations.OutputTimeUnit;
39+
import org.openjdk.jmh.annotations.Scope;
40+
import org.openjdk.jmh.annotations.Setup;
41+
import org.openjdk.jmh.annotations.State;
42+
import org.openjdk.jmh.annotations.Warmup;
43+
44+
import java.util.List;
45+
import java.util.Map;
46+
import java.util.concurrent.TimeUnit;
47+
import java.util.function.BiConsumer;
48+
import java.util.function.Function;
49+
50+
import static org.drools.benchmarks.dmn.util.DynamicTypeUtils.entry;
51+
import static org.drools.benchmarks.dmn.util.DynamicTypeUtils.prototype;
52+
53+
public abstract class AbstractCodegenBenchmark {
54+
55+
private DMNRuntime dmnRuntime;
56+
private DMNModel dmnModel;
57+
private DMNContext dmnContext;
58+
59+
protected abstract String getResource();
60+
protected abstract List<String> getAdditionalResources();
61+
protected abstract String getNameSpace();
62+
protected abstract String getModelName();
63+
protected abstract Map<String, Object> getInputData();
64+
65+
protected void setupModelAndContext() {
66+
Function<DMNCompilerConfiguration, DMNCompiler> dmnCompilerFn = dmnCompilerConfiguration -> {
67+
((DMNCompilerConfigurationImpl) dmnCompilerConfiguration).addFEELProfile(new DoCompileFEELProfile());
68+
return new DMNCompilerImpl(dmnCompilerConfiguration);
69+
};
70+
DMNRuntimeBuilder.DMNRuntimeBuilderConfigured dmnRuntimeBuilderConfigured = DMNRuntimeBuilder.fromDefaults()
71+
.buildConfigurationUsingCustomCompiler(dmnCompilerFn);
72+
Either<Exception, DMNRuntime> exceptionDMNRuntimeEither;
73+
if (getAdditionalResources() != null && !getAdditionalResources().isEmpty()) {
74+
exceptionDMNRuntimeEither = dmnRuntimeBuilderConfigured
75+
.fromClasspathResources(getResource(), this.getClass(), getAdditionalResources().toArray(new String[0]));
76+
} else {
77+
exceptionDMNRuntimeEither = dmnRuntimeBuilderConfigured
78+
.fromClasspathResource(getResource(), this.getClass());
79+
}
80+
dmnRuntime = exceptionDMNRuntimeEither
81+
.getOrElseThrow(e -> new RuntimeException("Error initializing DMNRuntime", e));
82+
((DMNRuntimeImpl) dmnRuntime).setOption(new RuntimeTypeCheckOption(true));
83+
dmnModel = dmnRuntime.getModel(
84+
getNameSpace(),
85+
getModelName());
86+
if (dmnModel == null) {
87+
throw new RuntimeException("Model " + getNameSpace() + "." + getModelName() + " not found");
88+
}
89+
dmnContext = dmnRuntime.newContext();
90+
getInputData().forEach((key, value) -> dmnContext.set(key, value));
91+
}
92+
93+
protected Object evaluateModelBenchmark() {
94+
return dmnRuntime.evaluateAll(dmnModel, dmnContext);
95+
}
96+
97+
98+
99+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.drools.benchmarks.dmn.codegen;
21+
22+
import org.openjdk.jmh.annotations.Benchmark;
23+
import org.openjdk.jmh.annotations.BenchmarkMode;
24+
import org.openjdk.jmh.annotations.Measurement;
25+
import org.openjdk.jmh.annotations.Mode;
26+
import org.openjdk.jmh.annotations.OutputTimeUnit;
27+
import org.openjdk.jmh.annotations.Scope;
28+
import org.openjdk.jmh.annotations.Setup;
29+
import org.openjdk.jmh.annotations.State;
30+
import org.openjdk.jmh.annotations.Warmup;
31+
32+
import java.util.List;
33+
import java.util.Map;
34+
import java.util.concurrent.TimeUnit;
35+
36+
import static org.drools.benchmarks.dmn.util.DynamicTypeUtils.entry;
37+
import static org.drools.benchmarks.dmn.util.DynamicTypeUtils.prototype;
38+
39+
@BenchmarkMode(Mode.AverageTime)
40+
@State(Scope.Thread)
41+
@Warmup(iterations = 100, time = 200, timeUnit = TimeUnit.MILLISECONDS)
42+
@Measurement(iterations = 20, time = 200, timeUnit = TimeUnit.MILLISECONDS)
43+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
44+
public class ImportedModelCodegenBenchmark extends AbstractCodegenBenchmark {
45+
46+
@Override
47+
protected String getResource() {
48+
return "dmn/Importing_EmptyNamed_Model_With_Href_Namespace.dmn";
49+
}
50+
51+
@Override
52+
protected List<String> getAdditionalResources() {
53+
return List.of("dmn/Imported_Model_Unamed.dmn");
54+
}
55+
56+
@Override
57+
protected String getNameSpace() {
58+
return "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
59+
}
60+
61+
@Override
62+
protected String getModelName() {
63+
return "Importing empty-named Model";
64+
}
65+
66+
@Override
67+
protected Map<String, Object> getInputData() {
68+
Map<String, Object> aPerson = prototype(entry("name", "John"), entry("age", 20));
69+
Map<String, Object> anImportedPerson = prototype(entry("name", "Luke"), entry("age", 35));
70+
return prototype(entry("A Person", aPerson), entry("An Imported Person", anImportedPerson));
71+
}
72+
73+
@Setup()
74+
public void setupModelAndContext() {
75+
super.setupModelAndContext();
76+
}
77+
78+
@Benchmark
79+
public Object evaluateModelBenchmark() {
80+
return super.evaluateModelBenchmark();
81+
}
82+
83+
public static void main(String[] args) throws Exception {
84+
ImportedModelCodegenBenchmark a = new ImportedModelCodegenBenchmark();
85+
a.setupModelAndContext();
86+
System.out.println(a.evaluateModelBenchmark());
87+
}
88+
89+
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.drools.benchmarks.dmn.codegen;
21+
22+
import org.openjdk.jmh.annotations.Benchmark;
23+
import org.openjdk.jmh.annotations.BenchmarkMode;
24+
import org.openjdk.jmh.annotations.Measurement;
25+
import org.openjdk.jmh.annotations.Mode;
26+
import org.openjdk.jmh.annotations.OutputTimeUnit;
27+
import org.openjdk.jmh.annotations.Scope;
28+
import org.openjdk.jmh.annotations.Setup;
29+
import org.openjdk.jmh.annotations.State;
30+
import org.openjdk.jmh.annotations.Warmup;
31+
32+
import java.util.List;
33+
import java.util.Map;
34+
import java.util.concurrent.TimeUnit;
35+
36+
import static org.drools.benchmarks.dmn.util.DynamicTypeUtils.entry;
37+
import static org.drools.benchmarks.dmn.util.DynamicTypeUtils.prototype;
38+
39+
@BenchmarkMode(Mode.AverageTime)
40+
@State(Scope.Thread)
41+
@Warmup(iterations = 100, time = 200, timeUnit = TimeUnit.MILLISECONDS)
42+
@Measurement(iterations = 20, time = 200, timeUnit = TimeUnit.MILLISECONDS)
43+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
44+
public class PrequalificationCodegenBenchmark extends AbstractCodegenBenchmark {
45+
46+
@Override
47+
protected String getResource() {
48+
return "dmn/Prequalification.dmn";
49+
}
50+
51+
@Override
52+
protected List<String> getAdditionalResources() {
53+
return null;
54+
}
55+
56+
@Override
57+
protected String getNameSpace() {
58+
return "http://www.trisotech.com/definitions/_f31e1f8e-d4ce-4a3a-ac3b-747efa6b3401";
59+
}
60+
61+
@Override
62+
protected String getModelName() {
63+
return "Prequalification";
64+
}
65+
66+
@Override
67+
protected Map<String, Object> getInputData() {
68+
Map<String, Object> borrower = prototype(entry("Monthly Income", 100), entry("Monthly Other Debt", 20));
69+
return prototype(entry("Credit Score", 350),
70+
entry("Loan Amount", 15),
71+
entry("Appraised Value", 10),
72+
entry("Best Rate", 5),
73+
entry("Borrower", borrower));
74+
}
75+
76+
@Setup()
77+
public void setupModelAndContext() {
78+
super.setupModelAndContext();
79+
}
80+
81+
@Benchmark
82+
public Object evaluateModelBenchmark() {
83+
return super.evaluateModelBenchmark();
84+
}
85+
86+
87+
public static void main(String[] args) throws Exception {
88+
PrequalificationCodegenBenchmark a = new PrequalificationCodegenBenchmark();
89+
a.setupModelAndContext();
90+
System.out.println(a.evaluateModelBenchmark());
91+
}
92+
93+
94+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
21+
<dmn:definitions xmlns="http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44"
22+
xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/"
23+
xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/"
24+
xmlns:dmndi="https://www.omg.org/spec/DMN/20230324/DMNDI/"
25+
xmlns:feel="https://www.omg.org/spec/DMN/20230324/FEEL/"
26+
xmlns:dmn="https://www.omg.org/spec/DMN/20230324/MODEL/"
27+
xmlns:tc="http://www.omg.org/spec/DMN/20160719/testcase"
28+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
29+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
30+
exporter="DMN Modeler"
31+
exporterVersion="6.0.3.201802231629"
32+
id="_f27bb64b-6fc7-4e1f-9848-11ba35e0df44"
33+
name="Imported Model"
34+
namespace="http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44">
35+
<dmn:extensionElements>
36+
</dmn:extensionElements>
37+
<dmn:itemDefinition id="_63824D3F-9173-446D-A940-6A7F0FA056BB" name="tPerson" isCollection="false">
38+
<dmn:itemComponent id="_9bb0759c-b3c1-482f-87f5-c047dc65cef0" name="name">
39+
<dmn:typeRef>string</dmn:typeRef>
40+
</dmn:itemComponent>
41+
<dmn:itemComponent id="_929acc15-101c-4e49-9b11-494fff411e50" name="age">
42+
<dmn:typeRef>number</dmn:typeRef>
43+
</dmn:itemComponent>
44+
</dmn:itemDefinition>
45+
<dmn:inputData id="_51190b90-924d-479b-872b-4c6f3486c2cb" name="A Person">
46+
<dmn:variable id="_44a44de4-c0ab-408e-9ba9-983d8ec2f6b5"
47+
name="A Person"
48+
typeRef="tPerson"/>
49+
</dmn:inputData>
50+
<dmn:inputData id="_51190b90-924d-479b-872b-4c6f3486c2de" name="An Imported Person">
51+
<dmn:variable id="_44a44de4-c0ab-408e-9ba9-983d8ec2f6c6"
52+
name="An Imported Person"
53+
typeRef="tPerson"/>
54+
</dmn:inputData>
55+
<dmn:decision id="_bf4a9628-15ae-4887-97f2-7099426cb61g" name="Remote Greeting">
56+
<dmn:variable id="_ecc6e0bb-a0af-4e99-aac6-5b8bed09c549"
57+
name="Remote Greeting"
58+
typeRef="string"/>
59+
<dmn:informationRequirement>
60+
<dmn:requiredInput href="#_51190b90-924d-479b-872b-4c6f3486c2de"/>
61+
</dmn:informationRequirement>
62+
<dmn:knowledgeRequirement>
63+
<dmn:requiredKnowledge href="#_32543811-b499-4608-b784-6c6f294b1c58"/>
64+
</dmn:knowledgeRequirement>
65+
<dmn:literalExpression xmlns:triso="http://www.trisotech.com/2015/triso/modeling"
66+
id="_d7e6836b-8491-487a-a653-5735daa85bf2"
67+
triso:unparsed="true">
68+
<dmn:text>Say Hello( An Imported Person )</dmn:text>
69+
</dmn:literalExpression>
70+
</dmn:decision>
71+
72+
<dmn:businessKnowledgeModel id="_32543811-b499-4608-b784-6c6f294b1c58" name="Say Hello">
73+
<dmn:variable id="_a8eb10e1-30e6-40d8-a564-a868f4e0af34"
74+
name="Say Hello"
75+
typeRef="string"/>
76+
<dmn:encapsulatedLogic kind="FEEL" id="_acbb96c9-34a3-4628-8179-dfc5f583e695">
77+
<dmn:formalParameter id="_4a626f74-2ecc-4759-b76a-04baec6b795d"
78+
name="Person"
79+
typeRef="tPerson"/>
80+
<dmn:literalExpression id="_c173a894-3719-4d2f-a365-25850e217310">
81+
<dmn:text>"Hello " + Person.name + "!"</dmn:text>
82+
</dmn:literalExpression>
83+
</dmn:encapsulatedLogic>
84+
</dmn:businessKnowledgeModel>
85+
86+
</dmn:definitions>

0 commit comments

Comments
 (0)