diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml index 9a30b127..3b31e4e0 100644 --- a/benchmarks/pom.xml +++ b/benchmarks/pom.xml @@ -59,6 +59,11 @@ cloudevents-kafka ${project.version} + + io.cloudevents + cloudevents-sql + ${project.version} + org.openjdk.jmh diff --git a/benchmarks/src/main/java/io/cloudevents/bench/sql/CompileBenchmark.java b/benchmarks/src/main/java/io/cloudevents/bench/sql/CompileBenchmark.java new file mode 100644 index 00000000..b6e26ef5 --- /dev/null +++ b/benchmarks/src/main/java/io/cloudevents/bench/sql/CompileBenchmark.java @@ -0,0 +1,35 @@ +package io.cloudevents.bench.sql; + +import io.cloudevents.sql.Parser; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.infra.Blackhole; + +public class CompileBenchmark { + + @Benchmark + @BenchmarkMode({Mode.Throughput, Mode.AverageTime}) + public void testCompileSmallExpression(Blackhole bh) { + bh.consume( + Parser.parseDefault("(a + b + c) = 10 AND TRUE OR CONCAT('1', '2', id) = '123'") + ); + } + + @Benchmark + @BenchmarkMode({Mode.Throughput, Mode.AverageTime}) + public void testCompileSmallTrueConstantExpression(Blackhole bh) { + bh.consume( + Parser.parseDefault("(1 + 2 + 3) = 10 AND TRUE OR CONCAT('1', '2', '3') = 123") + ); + } + + @Benchmark + @BenchmarkMode({Mode.Throughput, Mode.AverageTime}) + public void testCompileSmallFalseConstantExpression(Blackhole bh) { + bh.consume( + Parser.parseDefault("(1 + 2 + 3) = 10 AND FALSE OR CONCAT('1', '2', '3') = 124") + ); + } + +} diff --git a/benchmarks/src/main/java/io/cloudevents/bench/sql/RunBenchmark.java b/benchmarks/src/main/java/io/cloudevents/bench/sql/RunBenchmark.java new file mode 100644 index 00000000..876d2b50 --- /dev/null +++ b/benchmarks/src/main/java/io/cloudevents/bench/sql/RunBenchmark.java @@ -0,0 +1,92 @@ +package io.cloudevents.bench.sql; + +import io.cloudevents.CloudEvent; +import io.cloudevents.core.builder.CloudEventBuilder; +import io.cloudevents.sql.Expression; +import io.cloudevents.sql.Parser; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.infra.Blackhole; + +import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA_WITH_EXT; + +public class RunBenchmark { + + @State(Scope.Thread) + public static class TestCaseSmallExpression { + public CloudEvent event = CloudEventBuilder + .v1(V1_WITH_JSON_DATA_WITH_EXT) + .withExtension("a", "10") + .withExtension("b", 3) + .withExtension("c", "-3") + .build(); + public Expression expression = Parser + .parseDefault("(a + b + c) = 10 AND TRUE OR CONCAT('1', '2', id) = '123'"); + } + + @State(Scope.Thread) + public static class TestCaseSmallTrueConstantExpression { + public CloudEvent event = CloudEventBuilder + .v1(V1_WITH_JSON_DATA_WITH_EXT) + .build(); + public Expression expression = Parser + .parseDefault("(1 + 2 + 3) = 10 AND TRUE OR CONCAT('1', '2', '3') = 123"); + } + + @State(Scope.Thread) + public static class TestCaseSmallFalseConstantExpression { + public CloudEvent event = CloudEventBuilder + .v1(V1_WITH_JSON_DATA_WITH_EXT) + .build(); + public Expression expression = Parser + .parseDefault("(1 + 2 + 3) = 10 AND FALSE OR CONCAT('1', '2', '3') = 124"); + } + + @Benchmark + @BenchmarkMode({Mode.Throughput, Mode.AverageTime}) + public void testEvaluateSmallExpression(TestCaseSmallExpression testCase, Blackhole bh) { + bh.consume( + testCase.expression.evaluate(testCase.event) + ); + } + + @Benchmark + @BenchmarkMode({Mode.Throughput, Mode.AverageTime}) + public void testTryEvaluateSmallExpression(TestCaseSmallExpression testCase, Blackhole bh) { + bh.consume( + testCase.expression.tryEvaluate(testCase.event) + ); + } + + @Benchmark + @BenchmarkMode({Mode.Throughput, Mode.AverageTime}) + public void testEvaluateSmallTrueConstantExpression(TestCaseSmallTrueConstantExpression testCase, Blackhole bh) { + bh.consume( + testCase.expression.evaluate(testCase.event) + ); + } + + @Benchmark + @BenchmarkMode({Mode.Throughput, Mode.AverageTime}) + public void testTryEvaluateSmallTrueConstantExpression(TestCaseSmallTrueConstantExpression testCase, Blackhole bh) { + bh.consume( + testCase.expression.tryEvaluate(testCase.event) + ); + } + + @Benchmark + @BenchmarkMode({Mode.Throughput, Mode.AverageTime}) + public void testEvaluateSmallFalseConstantExpression(TestCaseSmallFalseConstantExpression testCase, Blackhole bh) { + bh.consume( + testCase.expression.evaluate(testCase.event) + ); + } + + @Benchmark + @BenchmarkMode({Mode.Throughput, Mode.AverageTime}) + public void testTryEvaluateSmallFalseConstantExpression(TestCaseSmallFalseConstantExpression testCase, Blackhole bh) { + bh.consume( + testCase.expression.tryEvaluate(testCase.event) + ); + } + +}