Skip to content

Commit aa2499e

Browse files
committed
Update bench-jmh
1 parent 14901d4 commit aa2499e

File tree

8 files changed

+119
-108
lines changed

8 files changed

+119
-108
lines changed

bench-jmh/pom.xml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<properties>
1313
<jmh.version>1.33</jmh.version>
14-
<avaje-jsonb.version>0.10-SNAPSHOT</avaje-jsonb.version>
14+
<avaje-jsonb.version>1.0-RC2</avaje-jsonb.version>
1515
<yasson.version>2.0.2</yasson.version>
1616
<java.release>17</java.release>
1717
<maven.compiler.source>17</maven.compiler.source>
@@ -35,16 +35,16 @@
3535
<artifactId>avaje-jsonb-jackson</artifactId>
3636
<version>${avaje-jsonb.version}</version>
3737
</dependency>
38-
<dependency>
39-
<groupId>io.avaje</groupId>
40-
<artifactId>avaje-jsonb-jakarta</artifactId>
41-
<version>${avaje-jsonb.version}</version>
42-
</dependency>
43-
<dependency>
44-
<groupId>io.avaje</groupId>
45-
<artifactId>avaje-jsonb-diesel</artifactId>
46-
<version>${avaje-jsonb.version}</version>
47-
</dependency>
38+
<!-- <dependency>-->
39+
<!-- <groupId>io.avaje</groupId>-->
40+
<!-- <artifactId>avaje-jsonb-jakarta</artifactId>-->
41+
<!-- <version>${avaje-jsonb.version}</version>-->
42+
<!-- </dependency>-->
43+
<!-- <dependency>-->
44+
<!-- <groupId>io.avaje</groupId>-->
45+
<!-- <artifactId>avaje-jsonb-diesel</artifactId>-->
46+
<!-- <version>${avaje-jsonb.version}</version>-->
47+
<!-- </dependency>-->
4848
<dependency>
4949
<groupId>io.avaje</groupId>
5050
<artifactId>avaje-jsonb-generator</artifactId>
@@ -118,18 +118,18 @@
118118
</plugin>
119119

120120
<!-- Don't upload any files from these project. JMH dependencies are approved only for testing purposes. -->
121-
<plugin>
122-
<artifactId>maven-deploy-plugin</artifactId>
123-
<configuration>
124-
<skip>true</skip>
125-
</configuration>
126-
</plugin>
127-
<plugin>
128-
<artifactId>maven-javadoc-plugin</artifactId>
129-
<configuration>
130-
<skip>true</skip>
131-
</configuration>
132-
</plugin>
121+
<!-- <plugin>-->
122+
<!-- <artifactId>maven-deploy-plugin</artifactId>-->
123+
<!-- <configuration>-->
124+
<!-- <skip>true</skip>-->
125+
<!-- </configuration>-->
126+
<!-- </plugin>-->
127+
<!-- <plugin>-->
128+
<!-- <artifactId>maven-javadoc-plugin</artifactId>-->
129+
<!-- <configuration>-->
130+
<!-- <skip>true</skip>-->
131+
<!-- </configuration>-->
132+
<!-- </plugin>-->
133133

134134
<!--run `java -jar bench-jmh.jar -h` for help -->
135135
<plugin>

bench-jmh/src/main/java/org/example/jmh/BigDecimalTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import io.avaje.jsonb.JsonType;
55
import io.avaje.jsonb.Jsonb;
6-
import io.avaje.jsonb.jackson.JacksonIOAdapter;
6+
import io.avaje.jsonb.jackson.JacksonAdapter;
77
import org.example.jmh.model.MyMathBigD;
88
import org.openjdk.jmh.annotations.*;
99

@@ -24,7 +24,7 @@ public class BigDecimalTest {
2424

2525
private static final ObjectMapper mapper = new ObjectMapper();
2626

27-
private static final Jsonb jsonbStandard = Jsonb.newBuilder().adapter(new JacksonIOAdapter()).build();
27+
private static final Jsonb jsonbStandard = Jsonb.newBuilder().adapter(new JacksonAdapter()).build();
2828
private static final JsonType<MyMathBigD> jsonbType = jsonbStandard.type(MyMathBigD.class);
2929

3030
private MyMathBigD testData;

bench-jmh/src/main/java/org/example/jmh/BigIntTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import io.avaje.jsonb.JsonType;
55
import io.avaje.jsonb.Jsonb;
6-
import io.avaje.jsonb.jackson.JacksonIOAdapter;
6+
import io.avaje.jsonb.jackson.JacksonAdapter;
77
import org.example.jmh.model.MyMathBigD;
88
import org.example.jmh.model.MyMathBigInt;
99
import org.openjdk.jmh.annotations.*;
@@ -26,7 +26,7 @@ public class BigIntTest {
2626

2727
private static final ObjectMapper mapper = new ObjectMapper();
2828

29-
private static final Jsonb jsonbStandard = Jsonb.newBuilder().adapter(new JacksonIOAdapter()).build();
29+
private static final Jsonb jsonbStandard = Jsonb.newBuilder().adapter(new JacksonAdapter()).build();
3030
private static final JsonType<MyMathBigInt> jsonbType = jsonbStandard.type(MyMathBigInt.class);
3131

3232
private MyMathBigInt testData;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.example.jmh;
2+
3+
import org.openjdk.jmh.annotations.*;
4+
import org.openjdk.jmh.runner.Runner;
5+
import org.openjdk.jmh.runner.options.Options;
6+
import org.openjdk.jmh.runner.options.OptionsBuilder;
7+
8+
import java.util.concurrent.locks.ReentrantLock;
9+
10+
public class LockTest {
11+
12+
private static Object lock = new Object();
13+
private static ReentrantLock reentrantLock = new ReentrantLock();
14+
15+
private static long cnt = 0;
16+
17+
@Benchmark
18+
@Measurement(iterations = 2)
19+
@Threads(10)
20+
@Fork(0)
21+
@Warmup(iterations = 5, time = 10)
22+
public void testWithoutLock(){
23+
doSomething();
24+
}
25+
26+
@Benchmark
27+
@Measurement(iterations = 2)
28+
@Threads(10)
29+
@Fork(0)
30+
@Warmup(iterations = 5, time = 10)
31+
public long testReentrantLock(){
32+
reentrantLock.lock();
33+
try {
34+
return doSomething();
35+
} finally {
36+
reentrantLock.unlock();
37+
}
38+
}
39+
40+
@Benchmark
41+
@Measurement(iterations = 2)
42+
@Threads(10)
43+
@Fork(0)
44+
@Warmup(iterations = 5, time = 10)
45+
public long testSynchronized(){
46+
synchronized (lock) {
47+
return doSomething();
48+
}
49+
}
50+
51+
private long doSomething() {
52+
cnt += 1;
53+
if (cnt == (Long.MAX_VALUE)) {
54+
cnt = 0;
55+
}
56+
return cnt;
57+
}
58+
59+
public static void main(String[] args) {
60+
Options options = new OptionsBuilder().include(LockTest.class.getSimpleName()).build();
61+
try {
62+
new Runner(options).run();
63+
} catch (Exception e) {
64+
65+
} finally {
66+
}
67+
}
68+
}

bench-jmh/src/main/java/org/example/jmh/NestSmallTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.fasterxml.jackson.databind.ObjectMapper;
88
import io.avaje.jsonb.JsonType;
99
import io.avaje.jsonb.Jsonb;
10-
import io.avaje.jsonb.jackson.JacksonIOAdapter;
10+
import io.avaje.jsonb.jackson.JacksonAdapter;
1111
import org.example.jmh.model.NarrowNamesRecord;
1212
import org.example.jmh.model.NestAddress;
1313
import org.example.jmh.model.NestCust;
@@ -31,7 +31,7 @@ public class NestSmallTest {
3131

3232
private static final ObjectMapper mapper = new ObjectMapper();
3333

34-
private static final Jsonb jsonbStandard = Jsonb.newBuilder().adapter(new JacksonIOAdapter()).build();
34+
private static final Jsonb jsonbStandard = Jsonb.newBuilder().adapter(new JacksonAdapter()).build();
3535
private static final JsonType<NestCust> jsonbNestCust = jsonbStandard.type(NestCust.class);
3636

3737
private NestCust testData;

bench-jmh/src/main/java/org/example/jmh/PropertyStrTenTest.java

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
import io.avaje.jsonb.JsonType;
99
import io.avaje.jsonb.JsonView;
1010
import io.avaje.jsonb.Jsonb;
11-
import io.avaje.jsonb.stream.DieselAdapter;
12-
import io.avaje.jsonb.jackson.JacksonIOAdapter;
13-
import io.avaje.jsonb.jakarta.JakartaIOAdapter;
11+
import io.avaje.jsonb.jackson.JacksonAdapter;
12+
import io.avaje.jsonb.stream.JsonStream;
1413
import org.example.jmh.model.OtherPropertyData;
1514
import org.example.jmh.model.SomePropertyData;
16-
import org.example.jmh.model.WideNamesRecord;
1715
import org.openjdk.jmh.annotations.*;
1816

1917
import java.io.IOException;
@@ -34,13 +32,10 @@ public class PropertyStrTenTest {
3432

3533
private static final ObjectMapper mapper = new ObjectMapper();
3634

37-
private static final Jsonb dieselJsonb = Jsonb.newBuilder().adapter(new DieselAdapter(false, false, false)).build();
35+
private static final Jsonb dieselJsonb = Jsonb.newBuilder().adapter(new JsonStream(false, false, false)).build();
3836
private static final JsonType<SomePropertyData> dieselJsonbType = dieselJsonb.type(SomePropertyData.class);
3937

40-
private static final Jsonb jakartaJsonb = Jsonb.newBuilder().adapter(new JakartaIOAdapter()).build();
41-
private static final JsonType<SomePropertyData> jakartaJsonbType = jakartaJsonb.type(SomePropertyData.class);
42-
43-
private static final Jsonb jsonb = Jsonb.newBuilder().adapter(new JacksonIOAdapter()).build();
38+
private static final Jsonb jsonb = Jsonb.newBuilder().adapter(new JacksonAdapter()).build();
4439
private static final JsonType<SomePropertyData> jsonbType = jsonb.type(SomePropertyData.class);
4540
private JsonView<SomePropertyData> allView;
4641
private JsonView<SomePropertyData> prop35View;
@@ -57,7 +52,7 @@ public class PropertyStrTenTest {
5752
@Setup
5853
public void setup() {
5954

60-
Jsonb viewAwareJsonb = Jsonb.newBuilder().adapter(new JacksonIOAdapter()).add(SomePropertyData.class, MyViewAdapter::new).build();
55+
Jsonb viewAwareJsonb = Jsonb.newBuilder().adapter(new JacksonAdapter()).add(SomePropertyData.class, MyViewAdapter::new).build();
6156
JsonType<SomePropertyData> viewAwareType = viewAwareJsonb.type(SomePropertyData.class);
6257
allView = viewAwareType.view("(*)");
6358
prop35View = viewAwareType.view("(anotherSimilarProperty3, lastButNotLeastProperty5)");
@@ -90,11 +85,6 @@ public String toJson_jsonb_jackson() {
9085
return jsonbType.toJson(testData);
9186
}
9287

93-
// @Benchmark
94-
public String toJson_jsonb_jakarta() {
95-
return jakartaJsonbType.toJson(testData);
96-
}
97-
9888
// @Benchmark
9989
public String toJson_jsonb_diesel() {
10090
return dieselJsonbType.toJson(testData);
@@ -188,31 +178,16 @@ public SomePropertyData fromJson_jsonb_jackson_reader() {
188178
return jsonbType.fromJson(new StringReader(content));
189179
}
190180

191-
@Benchmark
192-
public SomePropertyData fromJson_jsonb_jakarta() {
193-
return jakartaJsonbType.fromJson(content);
194-
}
195-
196181
@Benchmark
197182
public SomePropertyData fromJson_jsonb_diesel() {
198183
return dieselJsonbType.fromJson(content);
199184
}
200185

201-
// @Benchmark
202-
public SomePropertyData fromJson_jsonb_jakarta_reader() {
203-
return jakartaJsonbType.fromJson(new StringReader(content));
204-
}
205-
206186
// @Benchmark
207187
public SomePropertyData fromJson_jsonb_asBytes() {
208188
return jsonbType.fromJson(contentAsBytes);
209189
}
210190

211-
// @Benchmark
212-
public SomePropertyData fromJson_jsonb_asBytes_jakarta() {
213-
return jakartaJsonbType.fromJson(contentAsBytes);
214-
}
215-
216191
//@Benchmark
217192
public SomePropertyData fromJson_jsonb_withTypeLookup() {
218193
return jsonb.type(SomePropertyData.class).fromJson(content);
@@ -231,11 +206,9 @@ public static void main(String[] args) throws IOException {
231206

232207
SomePropertyData d0 = test.fromJson_jsonb_diesel();
233208
SomePropertyData d1 = test.fromJson_jsonb_jackson();
234-
SomePropertyData d2 = test.fromJson_jsonb_jakarta();
235209

236210
String s0 = test.toJson_jsonb_diesel();
237211
String s1 = test.toJson_jsonb_jackson();
238-
String s2 = test.toJson_jsonb_jakarta();
239212
String s3 = test.toJson_objectMapper();
240213

241214
// String asJson = test.toJson_jsonb_viewProp35();

0 commit comments

Comments
 (0)