This is an automated email from the ASF dual-hosted git repository.

tzimanyi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-benchmarks.git


The following commit(s) were added to refs/heads/main by this push:
     new 14b62259 [incubator-kie-issues#1350] Create AST benchmarks module to 
directly measure BaseNode's evaluation times. Implemented 
ForExpressionNodeBenchmark (#289)
14b62259 is described below

commit 14b622596ed20c1983d1375b5c78a65d41999f73
Author: Gabriele Cardosi <[email protected]>
AuthorDate: Thu Aug 15 10:42:30 2024 +0200

    [incubator-kie-issues#1350] Create AST benchmarks module to directly 
measure BaseNode's evaluation times. Implemented ForExpressionNodeBenchmark 
(#289)
    
    Co-authored-by: Gabriele-Cardosi <[email protected]>
---
 .../benchmarks/dmn/ast/AbstractASTBenchmark.java   | 82 ++++++++++++++++++++++
 .../dmn/ast/ForExpressionNodeBenchmark.java        | 37 ++++++++++
 2 files changed, 119 insertions(+)

diff --git 
a/drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/dmn/ast/AbstractASTBenchmark.java
 
b/drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/dmn/ast/AbstractASTBenchmark.java
new file mode 100644
index 00000000..0e17007c
--- /dev/null
+++ 
b/drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/dmn/ast/AbstractASTBenchmark.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License. 
+ */
+
+package org.drools.benchmarks.dmn.ast;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.FEELDialect;
+import org.kie.dmn.feel.lang.Type;
+import org.kie.dmn.feel.lang.ast.BaseNode;
+import org.kie.dmn.feel.lang.impl.EvaluationContextImpl;
+import org.kie.dmn.feel.parser.feel11.ASTBuilderVisitor;
+import org.kie.dmn.feel.parser.feel11.FEELParser;
+import org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser;
+import org.kie.dmn.feel.util.ClassLoaderUtil;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@State(Scope.Thread)
+@Warmup(iterations = 100, time = 200, timeUnit = TimeUnit.MILLISECONDS)
+@Measurement(iterations = 20, time = 200, timeUnit = TimeUnit.MILLISECONDS)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+public abstract class AbstractASTBenchmark {
+
+    private BaseNode baseNode;
+
+    @Setup()
+    public void setupBaseNode() {
+        baseNode = getBaseNode(getBaseNodeExpression());
+    }
+
+    protected abstract String getBaseNodeExpression();
+
+    @Benchmark
+    public Object evaluateBaseNodeBenchmark() {
+        return baseNode.evaluate(newEmptyEvaluationContext());
+    }
+
+    private static EvaluationContext newEmptyEvaluationContext() {
+        // Defaulting FEELDialect to FEEL
+        return new 
EvaluationContextImpl(ClassLoaderUtil.findDefaultClassLoader(), null, 
FEELDialect.FEEL);
+    }
+
+    private static BaseNode getBaseNode(String baseNodeExpression) {
+        Map<String, Type> inputTypes  = Collections.emptyMap();
+        FEEL_1_1Parser parser = FEELParser.parse(null, baseNodeExpression, 
inputTypes, Collections.emptyMap(), Collections.emptyList(), 
Collections.emptyList(), null);
+
+        ParseTree tree = parser.compilation_unit();
+
+        ASTBuilderVisitor v = new ASTBuilderVisitor(inputTypes, null);
+        return tree.accept(v);
+    }
+
+}
diff --git 
a/drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/dmn/ast/ForExpressionNodeBenchmark.java
 
b/drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/dmn/ast/ForExpressionNodeBenchmark.java
new file mode 100644
index 00000000..cd942aa3
--- /dev/null
+++ 
b/drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/dmn/ast/ForExpressionNodeBenchmark.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License. 
+ */
+
+package org.drools.benchmarks.dmn.ast;
+
+import org.openjdk.jmh.annotations.Param;
+
+public class ForExpressionNodeBenchmark extends AbstractASTBenchmark {
+
+    @Param({"for x in [ 1, 2, 3, 4 ] return x",
+            "for x in [ [1, 2], [3, 4] ] return x",
+            "for x in [ 1, 2, 3, 4 ], y in x return y",
+            "for x in [ [1,2], [3,4] ], y in x return y"
+    })
+    private String baseNodeExpression;
+
+    @Override
+    public String getBaseNodeExpression() {
+        return baseNodeExpression;
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to