CESQL Benchmark (#380)

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
This commit is contained in:
Francesco Guardiani 2021-04-30 11:01:02 +02:00 committed by GitHub
parent c8f10e9215
commit 3234e30e55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 132 additions and 0 deletions

View File

@ -59,6 +59,11 @@
<artifactId>cloudevents-kafka</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-sql</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>

View File

@ -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")
);
}
}

View File

@ -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)
);
}
}