Skip to content

Commit 4526d52

Browse files
committed
Update benchmark. Add static void main
1 parent e544896 commit 4526d52

File tree

6 files changed

+130
-8
lines changed

6 files changed

+130
-8
lines changed

Readme.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ Running trusty SimpleBenchmark and storing results in file trusty-results.json:
3030
cd trusty-benchmarks
3131
java -jar target/trusty-benchmarks.jar -jvmArgs "-Xms4g -Xmx4g" -foe true -rf json -rff trusty-results.json SimpleBenchmark
3232

33-
Running trusty SimpleBenchmark and storing results in file trusty-results.json:
33+
Running jpmml SimpleBenchmark and storing results in file trusty-results.json:
3434

3535
cd jpmml-benchmarks
3636
java -jar target/jpmml-benchmarks.jar -jvmArgs "-Xms4g -Xmx4g" -foe true -rf json -rff jpmml-results.json SimpleBenchmark
3737

38+
Running with async profiling
39+
40+
java -jar target/jpmml-benchmarks.jar -prof gc -jvmArgs "-Xms24g -Xmx24g" -foe true -rf json -rff jpmml-results.json SimpleBenchmark

jpmml-benchmark/src/main/java/org/kie/pmml/benchmark/jpmml/SimpleBenchmark.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929

3030
import static org.kie.pmml.benchmark.jpmml.Builder.getModelEvaluator;
3131

32-
@BenchmarkMode({Mode.Throughput, Mode.AverageTime, Mode.SampleTime, Mode.SingleShotTime})
32+
@BenchmarkMode(Mode.AverageTime)
3333
@State(Scope.Benchmark)
34-
@Warmup(iterations = 2)
34+
@Warmup(iterations = 10, time = 20)
3535
@Measurement(iterations = 5, time = 30)
3636
@OutputTimeUnit(TimeUnit.MILLISECONDS)
37-
@Fork(value = 1)
37+
@Fork(value = 2)
3838
public class SimpleBenchmark extends SimpleAbstractBenchmark {
3939

4040
private Map<FieldName, FieldValue> arguments;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2021 Red Hat, Inc. and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.kie.pmml.benchmark.jpmml;
17+
18+
import org.dmg.pmml.FieldName;
19+
import org.jpmml.evaluator.FieldValue;
20+
import org.jpmml.evaluator.InputField;
21+
import org.jpmml.evaluator.ModelEvaluator;
22+
import org.kie.pmml.benchmark.common.SimpleAbstractBenchmark;
23+
24+
import java.util.LinkedHashMap;
25+
import java.util.Map;
26+
import java.util.concurrent.atomic.AtomicInteger;
27+
28+
import static org.kie.pmml.benchmark.jpmml.Builder.getModelEvaluator;
29+
30+
public class SimpleMain extends SimpleAbstractBenchmark {
31+
32+
public static void main(String[] args) {
33+
AtomicInteger counter = new AtomicInteger();
34+
long startTime = System.currentTimeMillis();
35+
ModelEvaluator<?> evaluator = getModelEvaluator();
36+
long intermediateTime = System.currentTimeMillis();
37+
for (int i = 0; i < 1000; i++) {
38+
Map<FieldName, FieldValue> arguments = setupModel(evaluator);
39+
evaluate(evaluator, arguments, counter);
40+
}
41+
long stopTime = System.currentTimeMillis();
42+
System.out.println("ModelEvaluator instantiation took " + (intermediateTime - startTime) + " ms");
43+
System.out.println("Loop execution took " + (stopTime - intermediateTime) + " ms");
44+
}
45+
46+
private static Map<FieldName, FieldValue> setupModel(ModelEvaluator<?> evaluator) {
47+
Map<FieldName, FieldValue> toReturn = new LinkedHashMap<>();
48+
// Mapping the record field-by-field from data source schema to PMML schema
49+
for (InputField inputField : evaluator.getInputFields()) {
50+
FieldName inputName = inputField.getName();
51+
Object rawValue = ((Double)INPUT_DATA.get(inputName.getValue()) +0.1);
52+
// Transforming an arbitrary user-supplied value to a known-good PMML value
53+
FieldValue inputValue = inputField.prepare(rawValue);
54+
toReturn.put(inputName, inputValue);
55+
}
56+
return toReturn;
57+
}
58+
59+
private static void evaluate(ModelEvaluator<?> evaluator, Map<FieldName, FieldValue> arguments, AtomicInteger counter) {
60+
System.out.println(evaluator.evaluate(arguments).hashCode());
61+
System.out.println(counter.addAndGet(1));
62+
}
63+
64+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<version.jmh>1.21</version.jmh>
2222
<version.junit>4.13.1</version.junit>
2323
<version.sl4j>1.7.30</version.sl4j>
24-
<kie.version>7.52.0-SNAPSHOT</kie.version>
24+
<kie.version>7.53.0-SNAPSHOT</kie.version>
2525
</properties>
2626

2727
<build>

trusty-benchmark/src/main/java/org/kie/pmml/benchmark/trusty/SimpleBenchmark.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727

2828
import static org.kie.pmml.benchmark.trusty.Builder.getPMMLRuntime;
2929

30-
@BenchmarkMode({Mode.Throughput, Mode.AverageTime, Mode.SampleTime, Mode.SingleShotTime})
30+
@BenchmarkMode(Mode.AverageTime)
3131
@State(Scope.Benchmark)
32-
@Warmup(iterations = 2)
32+
@Warmup(iterations = 10, time = 20)
3333
@Measurement(iterations = 5, time = 30)
3434
@OutputTimeUnit(TimeUnit.MILLISECONDS)
35-
@Fork(value = 1)
35+
@Fork(value = 2)
3636
public class SimpleBenchmark extends SimpleAbstractBenchmark {
3737

3838
private PMMLContext pmmlContext;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2021 Red Hat, Inc. and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.kie.pmml.benchmark.trusty;
17+
18+
import org.kie.api.pmml.PMMLRequestData;
19+
import org.kie.pmml.api.runtime.PMMLContext;
20+
import org.kie.pmml.api.runtime.PMMLRuntime;
21+
import org.kie.pmml.benchmark.common.SimpleAbstractBenchmark;
22+
import org.kie.pmml.evaluator.core.PMMLContextImpl;
23+
24+
import java.util.concurrent.atomic.AtomicInteger;
25+
26+
import static org.kie.pmml.benchmark.trusty.Builder.getPMMLRuntime;
27+
28+
public class SimpleMain extends SimpleAbstractBenchmark {
29+
30+
public static void main(String[] args) {
31+
AtomicInteger counter = new AtomicInteger();
32+
long startTime = System.currentTimeMillis();
33+
PMMLRuntime pmmlRuntime = getPMMLRuntime();
34+
long intermediateTime = System.currentTimeMillis();
35+
for (int i = 0; i < 1000; i++) {
36+
PMMLContext pmmlContext = setupModel();
37+
evaluate(pmmlRuntime, pmmlContext, counter);
38+
}
39+
long stopTime = System.currentTimeMillis();
40+
System.out.println("PMMLRuntime instantiation took " + (intermediateTime - startTime) + " ms");
41+
System.out.println("Loop execution took " + (stopTime - intermediateTime) + " ms");
42+
}
43+
44+
private static PMMLContext setupModel() {
45+
PMMLRequestData pmmlRequestData = new PMMLRequestData("123", MODEL_NAME);
46+
INPUT_DATA.forEach((s, o) -> pmmlRequestData.addRequestParam(s, ((Double) o) + 0.1));
47+
return new PMMLContextImpl(pmmlRequestData);
48+
}
49+
50+
private static void evaluate(PMMLRuntime pmmlRuntime, PMMLContext pmmlContext, AtomicInteger counter) {
51+
System.out.println(pmmlRuntime.evaluate(MODEL_NAME, pmmlContext).hashCode());
52+
System.out.println(counter.addAndGet(1));
53+
}
54+
55+
}

0 commit comments

Comments
 (0)