-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add benchmark module and test implicit cast Signed-off-by: Chen Dai <[email protected]> * Benchmark the second approach from Yury Signed-off-by: Chen Dai <[email protected]> * Refactor code to make benchmark module for future use Signed-off-by: Chen Dai <[email protected]> * Add readme Signed-off-by: Chen Dai <[email protected]> * Move benchmark class to right source location Signed-off-by: Chen Dai <[email protected]> * Change depedency accessiblity from api to impl Signed-off-by: Chen Dai <[email protected]> Signed-off-by: Chen Dai <[email protected]>
- Loading branch information
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# OpenSearch SQL/PPL Microbenchmark Suite | ||
|
||
This directory contains the microbenchmark suite of OpenSearch SQL/PPL. It relies on [JMH](http://openjdk.java.net/projects/code-tools/jmh/). | ||
|
||
## Purpose | ||
|
||
Microbenchmarks are intended to spot performance regressions in performance-critical components. | ||
|
||
The microbenchmark suite is also handy for ad-hoc microbenchmarks but please remove them again before merging your PR. | ||
|
||
## Getting Started | ||
|
||
Just run `./gradlew :benchmarks:jmh` from the project root directory or run specific benchmark via your IDE. It will build all microbenchmarks, execute them and print the result. | ||
|
||
## Adding Microbenchmarks | ||
|
||
Before adding a new microbenchmark, make yourself familiar with the JMH API. You can check our existing microbenchmarks and also the [JMH samples](http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/). | ||
|
||
In contrast to tests, the actual name of the benchmark class is not relevant to JMH. However, stick to the naming convention and end the class name of a benchmark with `Benchmark`. To have JMH execute a benchmark, annotate the respective methods with `@Benchmark`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
plugins { | ||
id 'java-library' | ||
id "me.champeau.jmh" version "0.6.8" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation project(':core') | ||
|
||
// Dependencies required by JMH micro benchmark | ||
api group: 'org.openjdk.jmh', name: 'jmh-core', version: '1.36' | ||
annotationProcessor group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: '1.36' | ||
} | ||
|
||
compileJava.options.compilerArgs.addAll(["-processor", "org.openjdk.jmh.generators.BenchmarkProcessor"]) |
73 changes: 73 additions & 0 deletions
73
...mh/java/org/opensearch/sql/expression/operator/predicate/ComparisonOperatorBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.expression.operator.predicate; | ||
|
||
import static org.opensearch.sql.data.model.ExprValueUtils.fromObjectValue; | ||
import static org.opensearch.sql.data.model.ExprValueUtils.integerValue; | ||
import static org.opensearch.sql.data.model.ExprValueUtils.stringValue; | ||
import static org.opensearch.sql.data.type.ExprCoreType.DATE; | ||
import static org.opensearch.sql.expression.DSL.literal; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Function; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.opensearch.sql.data.model.ExprValue; | ||
import org.opensearch.sql.expression.DSL; | ||
import org.opensearch.sql.expression.Expression; | ||
import org.opensearch.sql.expression.FunctionExpression; | ||
|
||
@Warmup(iterations = 1) | ||
@Measurement(iterations = 3) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@State(Scope.Thread) | ||
@Fork(value = 1) | ||
public class ComparisonOperatorBenchmark { | ||
|
||
@Param(value = { "int", "string", "date" }) | ||
private String testDataType; | ||
|
||
private final Map<String, ExprValue> params = | ||
ImmutableMap.<String, ExprValue>builder() | ||
.put("int", integerValue(1)) | ||
.put("string", stringValue("hello")) | ||
.put("date", fromObjectValue("2022-01-12", DATE)) | ||
.build(); | ||
|
||
@Benchmark | ||
public void testEqualOperator() { | ||
run(DSL::equal); | ||
} | ||
|
||
@Benchmark | ||
public void testLessOperator() { | ||
run(DSL::less); | ||
} | ||
|
||
@Benchmark | ||
public void testGreaterOperator() { | ||
run(DSL::greater); | ||
} | ||
|
||
private void run(Function<Expression[], FunctionExpression> dsl) { | ||
ExprValue param = params.get(testDataType); | ||
FunctionExpression func = dsl.apply(new Expression[] { | ||
literal(param), literal(param) | ||
}); | ||
func.valueOf(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ include 'doctest' | |
include 'legacy' | ||
include 'sql' | ||
include 'prometheus' | ||
include 'benchmarks' |