Skip to content

Commit 3234e30

Browse files
CESQL Benchmark (#380)
Signed-off-by: Francesco Guardiani <[email protected]>
1 parent c8f10e9 commit 3234e30

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

benchmarks/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
<artifactId>cloudevents-kafka</artifactId>
6060
<version>${project.version}</version>
6161
</dependency>
62+
<dependency>
63+
<groupId>io.cloudevents</groupId>
64+
<artifactId>cloudevents-sql</artifactId>
65+
<version>${project.version}</version>
66+
</dependency>
6267

6368
<dependency>
6469
<groupId>org.openjdk.jmh</groupId>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.cloudevents.bench.sql;
2+
3+
import io.cloudevents.sql.Parser;
4+
import org.openjdk.jmh.annotations.Benchmark;
5+
import org.openjdk.jmh.annotations.BenchmarkMode;
6+
import org.openjdk.jmh.annotations.Mode;
7+
import org.openjdk.jmh.infra.Blackhole;
8+
9+
public class CompileBenchmark {
10+
11+
@Benchmark
12+
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
13+
public void testCompileSmallExpression(Blackhole bh) {
14+
bh.consume(
15+
Parser.parseDefault("(a + b + c) = 10 AND TRUE OR CONCAT('1', '2', id) = '123'")
16+
);
17+
}
18+
19+
@Benchmark
20+
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
21+
public void testCompileSmallTrueConstantExpression(Blackhole bh) {
22+
bh.consume(
23+
Parser.parseDefault("(1 + 2 + 3) = 10 AND TRUE OR CONCAT('1', '2', '3') = 123")
24+
);
25+
}
26+
27+
@Benchmark
28+
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
29+
public void testCompileSmallFalseConstantExpression(Blackhole bh) {
30+
bh.consume(
31+
Parser.parseDefault("(1 + 2 + 3) = 10 AND FALSE OR CONCAT('1', '2', '3') = 124")
32+
);
33+
}
34+
35+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package io.cloudevents.bench.sql;
2+
3+
import io.cloudevents.CloudEvent;
4+
import io.cloudevents.core.builder.CloudEventBuilder;
5+
import io.cloudevents.sql.Expression;
6+
import io.cloudevents.sql.Parser;
7+
import org.openjdk.jmh.annotations.*;
8+
import org.openjdk.jmh.infra.Blackhole;
9+
10+
import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA_WITH_EXT;
11+
12+
public class RunBenchmark {
13+
14+
@State(Scope.Thread)
15+
public static class TestCaseSmallExpression {
16+
public CloudEvent event = CloudEventBuilder
17+
.v1(V1_WITH_JSON_DATA_WITH_EXT)
18+
.withExtension("a", "10")
19+
.withExtension("b", 3)
20+
.withExtension("c", "-3")
21+
.build();
22+
public Expression expression = Parser
23+
.parseDefault("(a + b + c) = 10 AND TRUE OR CONCAT('1', '2', id) = '123'");
24+
}
25+
26+
@State(Scope.Thread)
27+
public static class TestCaseSmallTrueConstantExpression {
28+
public CloudEvent event = CloudEventBuilder
29+
.v1(V1_WITH_JSON_DATA_WITH_EXT)
30+
.build();
31+
public Expression expression = Parser
32+
.parseDefault("(1 + 2 + 3) = 10 AND TRUE OR CONCAT('1', '2', '3') = 123");
33+
}
34+
35+
@State(Scope.Thread)
36+
public static class TestCaseSmallFalseConstantExpression {
37+
public CloudEvent event = CloudEventBuilder
38+
.v1(V1_WITH_JSON_DATA_WITH_EXT)
39+
.build();
40+
public Expression expression = Parser
41+
.parseDefault("(1 + 2 + 3) = 10 AND FALSE OR CONCAT('1', '2', '3') = 124");
42+
}
43+
44+
@Benchmark
45+
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
46+
public void testEvaluateSmallExpression(TestCaseSmallExpression testCase, Blackhole bh) {
47+
bh.consume(
48+
testCase.expression.evaluate(testCase.event)
49+
);
50+
}
51+
52+
@Benchmark
53+
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
54+
public void testTryEvaluateSmallExpression(TestCaseSmallExpression testCase, Blackhole bh) {
55+
bh.consume(
56+
testCase.expression.tryEvaluate(testCase.event)
57+
);
58+
}
59+
60+
@Benchmark
61+
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
62+
public void testEvaluateSmallTrueConstantExpression(TestCaseSmallTrueConstantExpression testCase, Blackhole bh) {
63+
bh.consume(
64+
testCase.expression.evaluate(testCase.event)
65+
);
66+
}
67+
68+
@Benchmark
69+
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
70+
public void testTryEvaluateSmallTrueConstantExpression(TestCaseSmallTrueConstantExpression testCase, Blackhole bh) {
71+
bh.consume(
72+
testCase.expression.tryEvaluate(testCase.event)
73+
);
74+
}
75+
76+
@Benchmark
77+
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
78+
public void testEvaluateSmallFalseConstantExpression(TestCaseSmallFalseConstantExpression testCase, Blackhole bh) {
79+
bh.consume(
80+
testCase.expression.evaluate(testCase.event)
81+
);
82+
}
83+
84+
@Benchmark
85+
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
86+
public void testTryEvaluateSmallFalseConstantExpression(TestCaseSmallFalseConstantExpression testCase, Blackhole bh) {
87+
bh.consume(
88+
testCase.expression.tryEvaluate(testCase.event)
89+
);
90+
}
91+
92+
}

0 commit comments

Comments
 (0)