Skip to content

Commit d4ee5a6

Browse files
Benchmarks (#192)
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
1 parent e71cc53 commit d4ee5a6

File tree

6 files changed

+442
-0
lines changed

6 files changed

+442
-0
lines changed

benchmarks/pom.xml

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<!--
4+
~ Copyright 2018-Present The CloudEvents Authors
5+
~ <p>
6+
~ Licensed under the Apache License, Version 2.0 (the "License");
7+
~ you may not use this file except in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~ <p>
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~ <p>
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
~
18+
-->
19+
<modelVersion>4.0.0</modelVersion>
20+
21+
<parent>
22+
<groupId>io.cloudevents</groupId>
23+
<artifactId>cloudevents-parent</artifactId>
24+
<version>2.0.0-SNAPSHOT</version>
25+
</parent>
26+
27+
<artifactId>cloudevents-benchmarks</artifactId>
28+
<packaging>jar</packaging>
29+
<name>CloudEvents - Benchmarks</name>
30+
31+
<properties>
32+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
33+
<jmh.version>1.23</jmh.version>
34+
<javac.target>1.8</javac.target>
35+
<!-- Name of the benchmark Uber-JAR to generate. -->
36+
<uberjar.name>benchmarks</uberjar.name>
37+
</properties>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>io.cloudevents</groupId>
42+
<artifactId>cloudevents-core</artifactId>
43+
<version>${project.version}</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>io.cloudevents</groupId>
47+
<artifactId>cloudevents-core</artifactId>
48+
<version>${project.version}</version>
49+
<type>test-jar</type>
50+
</dependency>
51+
<dependency>
52+
<groupId>io.cloudevents</groupId>
53+
<artifactId>cloudevents-json-jackson</artifactId>
54+
<version>${project.version}</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>io.cloudevents</groupId>
58+
<artifactId>cloudevents-kafka</artifactId>
59+
<version>${project.version}</version>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>org.openjdk.jmh</groupId>
64+
<artifactId>jmh-core</artifactId>
65+
<version>${jmh.version}</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.openjdk.jmh</groupId>
69+
<artifactId>jmh-generator-annprocess</artifactId>
70+
<version>${jmh.version}</version>
71+
<scope>provided</scope>
72+
</dependency>
73+
</dependencies>
74+
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-compiler-plugin</artifactId>
80+
<version>3.8.0</version>
81+
<configuration>
82+
<compilerVersion>${javac.target}</compilerVersion>
83+
<source>${javac.target}</source>
84+
<target>${javac.target}</target>
85+
</configuration>
86+
</plugin>
87+
<plugin>
88+
<groupId>org.apache.maven.plugins</groupId>
89+
<artifactId>maven-shade-plugin</artifactId>
90+
<version>3.2.1</version>
91+
<executions>
92+
<execution>
93+
<phase>package</phase>
94+
<goals>
95+
<goal>shade</goal>
96+
</goals>
97+
<configuration>
98+
<finalName>${uberjar.name}</finalName>
99+
<transformers>
100+
<transformer
101+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
102+
<mainClass>org.openjdk.jmh.Main</mainClass>
103+
</transformer>
104+
<transformer
105+
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
106+
</transformers>
107+
<filters>
108+
<filter>
109+
<!--
110+
Shading signed JARs will fail without this.
111+
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
112+
-->
113+
<artifact>*:*</artifact>
114+
<excludes>
115+
<exclude>META-INF/*.SF</exclude>
116+
<exclude>META-INF/*.DSA</exclude>
117+
<exclude>META-INF/*.RSA</exclude>
118+
</excludes>
119+
</filter>
120+
</filters>
121+
</configuration>
122+
</execution>
123+
</executions>
124+
</plugin>
125+
</plugins>
126+
<pluginManagement>
127+
<plugins>
128+
<plugin>
129+
<artifactId>maven-clean-plugin</artifactId>
130+
<version>2.5</version>
131+
</plugin>
132+
<plugin>
133+
<artifactId>maven-deploy-plugin</artifactId>
134+
<version>2.8.1</version>
135+
</plugin>
136+
<plugin>
137+
<artifactId>maven-install-plugin</artifactId>
138+
<version>2.5.1</version>
139+
</plugin>
140+
<plugin>
141+
<artifactId>maven-jar-plugin</artifactId>
142+
<version>2.4</version>
143+
</plugin>
144+
<plugin>
145+
<artifactId>maven-javadoc-plugin</artifactId>
146+
<version>2.9.1</version>
147+
</plugin>
148+
<plugin>
149+
<artifactId>maven-resources-plugin</artifactId>
150+
<version>2.6</version>
151+
</plugin>
152+
<plugin>
153+
<artifactId>maven-site-plugin</artifactId>
154+
<version>3.3</version>
155+
</plugin>
156+
<plugin>
157+
<artifactId>maven-source-plugin</artifactId>
158+
<version>2.2.1</version>
159+
</plugin>
160+
<plugin>
161+
<artifactId>maven-surefire-plugin</artifactId>
162+
<version>2.17</version>
163+
</plugin>
164+
</plugins>
165+
</pluginManagement>
166+
</build>
167+
168+
</project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2018-Present The CloudEvents Authors
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package io.cloudevents.bench.jackson;
19+
20+
import io.cloudevents.jackson.JsonFormat;
21+
import org.openjdk.jmh.annotations.*;
22+
import org.openjdk.jmh.infra.Blackhole;
23+
24+
import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA_WITH_EXT;
25+
import static io.cloudevents.core.test.Data.V1_WITH_XML_DATA;
26+
27+
public class JsonFormatDeserializationBenchmark {
28+
29+
@State(Scope.Thread)
30+
public static class DeserializationState {
31+
32+
public byte[] eventWithJson;
33+
public byte[] eventWithXml;
34+
public JsonFormat format = new JsonFormat();
35+
36+
public DeserializationState() {
37+
eventWithJson = format.serialize(V1_WITH_JSON_DATA_WITH_EXT);
38+
eventWithXml = format.serialize(V1_WITH_XML_DATA);
39+
}
40+
}
41+
42+
@Benchmark
43+
@BenchmarkMode(Mode.Throughput)
44+
public void deserializeWithJsonData(DeserializationState state, Blackhole bh) {
45+
bh.consume(
46+
state.format.deserialize(state.eventWithJson)
47+
);
48+
}
49+
50+
@Benchmark
51+
@BenchmarkMode(Mode.Throughput)
52+
public void deserializeWithXmlData(DeserializationState state, Blackhole bh) {
53+
bh.consume(
54+
state.format.deserialize(state.eventWithXml)
55+
);
56+
}
57+
58+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2018-Present The CloudEvents Authors
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package io.cloudevents.bench.jackson;
19+
20+
import io.cloudevents.CloudEvent;
21+
import io.cloudevents.core.builder.CloudEventBuilder;
22+
import io.cloudevents.jackson.JsonFormat;
23+
import org.openjdk.jmh.annotations.*;
24+
import org.openjdk.jmh.infra.Blackhole;
25+
26+
import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA_WITH_EXT;
27+
import static io.cloudevents.core.test.Data.V1_WITH_XML_DATA;
28+
29+
public class JsonFormatSerializationBenchmark {
30+
31+
@State(Scope.Thread)
32+
public static class SerializationState {
33+
public CloudEvent eventWithJson = CloudEventBuilder.v1(V1_WITH_JSON_DATA_WITH_EXT).build();
34+
public CloudEvent eventWithXml = CloudEventBuilder.v1(V1_WITH_XML_DATA).build();
35+
public JsonFormat format = new JsonFormat();
36+
}
37+
38+
@Benchmark
39+
@BenchmarkMode(Mode.Throughput)
40+
public void serializeWithJsonData(SerializationState state, Blackhole bh) {
41+
bh.consume(
42+
state.format.serialize(state.eventWithJson)
43+
);
44+
}
45+
46+
@Benchmark
47+
@BenchmarkMode(Mode.Throughput)
48+
public void serializeWithXmlData(SerializationState state, Blackhole bh) {
49+
bh.consume(
50+
state.format.serialize(state.eventWithXml)
51+
);
52+
}
53+
54+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2018-Present The CloudEvents Authors
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package io.cloudevents.bench.kafka;
19+
20+
import io.cloudevents.CloudEvent;
21+
import io.cloudevents.core.builder.CloudEventBuilder;
22+
import io.cloudevents.jackson.JsonFormat;
23+
import io.cloudevents.kafka.KafkaMessageFactory;
24+
import org.openjdk.jmh.annotations.*;
25+
import org.openjdk.jmh.infra.Blackhole;
26+
27+
import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA_WITH_EXT;
28+
29+
30+
public class CloudEventToKafkaProducerMessageBenchmark {
31+
32+
@State(Scope.Thread)
33+
public static class Event {
34+
public CloudEvent event = CloudEventBuilder.v1(V1_WITH_JSON_DATA_WITH_EXT).build();
35+
}
36+
37+
@Benchmark
38+
@BenchmarkMode(Mode.Throughput)
39+
public void testBinaryEncoding(Event event, Blackhole bh) {
40+
bh.consume(
41+
KafkaMessageFactory
42+
.createWriter("aaa")
43+
.writeBinary(event.event)
44+
);
45+
}
46+
47+
@Benchmark
48+
@BenchmarkMode(Mode.Throughput)
49+
public void testStructuredJsonEncoding(Event event, Blackhole bh) {
50+
bh.consume(
51+
KafkaMessageFactory
52+
.createWriter("aaa")
53+
.writeStructured(event.event, JsonFormat.CONTENT_TYPE)
54+
);
55+
}
56+
57+
}

0 commit comments

Comments
 (0)