Skip to content

Commit fd2d468

Browse files
committed
add with_object_list
1 parent 82727e1 commit fd2d468

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+6357
-380
lines changed

Diff for: src/main/java/com/jsoniter/benchmark/ExternalSerialization.java

+460-36
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.jsoniter.benchmark.with_10_double_fields;
2+
3+
import com.dslplatform.json.JsonWriter;
4+
import com.jsoniter.benchmark.All;
5+
import com.jsoniter.benchmark.ExternalSerialization;
6+
import org.openjdk.jmh.Main;
7+
import org.openjdk.jmh.annotations.*;
8+
import org.openjdk.jmh.infra.BenchmarkParams;
9+
import org.openjdk.jmh.infra.Blackhole;
10+
import org.openjdk.jmh.runner.RunnerException;
11+
12+
import java.io.ByteArrayOutputStream;
13+
import java.io.IOException;
14+
import java.util.concurrent.TimeUnit;
15+
16+
/*
17+
Benchmark Mode Cnt Score Error Units
18+
SerDslJson.ser avgt 5 1483965.621 ± 17904.051 ns/op
19+
*/
20+
@State(Scope.Thread)
21+
public class SerDslJson {
22+
23+
private JsonWriter jsonWriter;
24+
private ByteArrayOutputStream byteArrayOutputStream;
25+
private TestObject testObject;
26+
27+
@Setup(Level.Trial)
28+
public void benchSetup(BenchmarkParams params) {
29+
testObject = TestObject.createTestObject();
30+
jsonWriter = new JsonWriter();
31+
byteArrayOutputStream = new ByteArrayOutputStream();
32+
}
33+
34+
@Benchmark
35+
@BenchmarkMode(Mode.AverageTime)
36+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
37+
public void ser(Blackhole bh) throws IOException {
38+
for (int i = 0; i < 1000; i++) {
39+
jsonWriter.reset();
40+
byteArrayOutputStream.reset();
41+
ExternalSerialization.serialize(testObject, jsonWriter, false);
42+
jsonWriter.toStream(byteArrayOutputStream);
43+
bh.consume(byteArrayOutputStream);
44+
}
45+
}
46+
47+
public static void main(String[] args) throws IOException, RunnerException {
48+
All.loadJMH();
49+
Main.main(new String[]{
50+
"with_10_double_fields.SerDslJson",
51+
"-i", "5",
52+
"-wi", "5",
53+
"-f", "1",
54+
});
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.jsoniter.benchmark.with_10_double_fields;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
5+
import com.jsoniter.benchmark.All;
6+
import org.openjdk.jmh.Main;
7+
import org.openjdk.jmh.annotations.*;
8+
import org.openjdk.jmh.infra.BenchmarkParams;
9+
import org.openjdk.jmh.infra.Blackhole;
10+
import org.openjdk.jmh.runner.RunnerException;
11+
12+
import java.io.ByteArrayOutputStream;
13+
import java.io.IOException;
14+
import java.util.concurrent.TimeUnit;
15+
16+
/*
17+
Benchmark Mode Cnt Score Error Units
18+
SerJackson.ser avgt 5 1822478.053 ± 28609.935 ns/op
19+
*/
20+
@State(Scope.Thread)
21+
public class SerJackson {
22+
23+
private ObjectMapper objectMapper;
24+
private ByteArrayOutputStream byteArrayOutputStream;
25+
private TestObject testObject;
26+
27+
@Setup(Level.Trial)
28+
public void benchSetup(BenchmarkParams params) {
29+
objectMapper = new ObjectMapper();
30+
objectMapper.registerModule(new AfterburnerModule());
31+
byteArrayOutputStream = new ByteArrayOutputStream();
32+
testObject = TestObject.createTestObject();
33+
}
34+
35+
@Benchmark
36+
@BenchmarkMode(Mode.AverageTime)
37+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
38+
public void ser(Blackhole bh) throws IOException {
39+
for (int i = 0; i < 1000; i++) {
40+
byteArrayOutputStream.reset();
41+
objectMapper.writeValue(byteArrayOutputStream, testObject);
42+
bh.consume(byteArrayOutputStream);
43+
}
44+
}
45+
46+
public static void main(String[] args) throws IOException, RunnerException {
47+
All.loadJMH();
48+
Main.main(new String[]{
49+
"with_10_double_fields.SerJackson",
50+
"-i", "5",
51+
"-wi", "5",
52+
"-f", "1",
53+
});
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.jsoniter.benchmark.with_10_double_fields;
2+
3+
import com.jsoniter.DecodingMode;
4+
import com.jsoniter.JsonIterator;
5+
import com.jsoniter.benchmark.All;
6+
import com.jsoniter.output.EncodingMode;
7+
import com.jsoniter.output.JsonStream;
8+
import org.junit.Test;
9+
import org.openjdk.jmh.Main;
10+
import org.openjdk.jmh.annotations.*;
11+
import org.openjdk.jmh.infra.BenchmarkParams;
12+
import org.openjdk.jmh.infra.Blackhole;
13+
import org.openjdk.jmh.runner.RunnerException;
14+
15+
import java.io.ByteArrayOutputStream;
16+
import java.io.IOException;
17+
import java.util.concurrent.TimeUnit;
18+
19+
import static org.junit.Assert.assertEquals;
20+
21+
/*
22+
Benchmark Mode Cnt Score Error Units
23+
SerJsoniter.ser avgt 5 280252.226 ± 3812.810 ns/op
24+
*/
25+
@State(Scope.Thread)
26+
public class SerJsoniter {
27+
28+
private TestObject testObject;
29+
private JsonStream stream;
30+
private ByteArrayOutputStream byteArrayOutputStream;
31+
32+
@Setup(Level.Trial)
33+
public void benchSetup(BenchmarkParams params) {
34+
JsonStream.setMode(EncodingMode.DYNAMIC_MODE);
35+
JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH);
36+
testObject = TestObject.createTestObject();
37+
stream = new JsonStream(null, 512);
38+
byteArrayOutputStream = new ByteArrayOutputStream();
39+
}
40+
41+
@Benchmark
42+
@BenchmarkMode(Mode.AverageTime)
43+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
44+
public void ser(Blackhole bh) throws IOException {
45+
for (int i = 0; i < 1000; i++) {
46+
byteArrayOutputStream.reset();
47+
stream.reset(byteArrayOutputStream);
48+
stream.writeVal(testObject);
49+
stream.flush();
50+
bh.consume(byteArrayOutputStream);
51+
}
52+
}
53+
54+
@Test
55+
public void test() throws IOException {
56+
benchSetup(null);
57+
byteArrayOutputStream.reset();
58+
stream.reset(byteArrayOutputStream);
59+
stream.writeVal(testObject);
60+
stream.flush();
61+
assertEquals("{\"field1\":\"\"}", byteArrayOutputStream.toString());
62+
}
63+
64+
public static void main(String[] args) throws IOException, RunnerException {
65+
All.loadJMH();
66+
Main.main(new String[]{
67+
"with_10_double_fields.SerJsoniter",
68+
"-i", "5",
69+
"-wi", "5",
70+
"-f", "1",
71+
});
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.jsoniter.benchmark.with_10_double_fields;
2+
3+
import com.google.protobuf.InvalidProtocolBufferException;
4+
import com.jsoniter.benchmark.All;
5+
import org.junit.Test;
6+
import org.openjdk.jmh.Main;
7+
import org.openjdk.jmh.annotations.*;
8+
import org.openjdk.jmh.infra.BenchmarkParams;
9+
import org.openjdk.jmh.infra.Blackhole;
10+
import org.openjdk.jmh.runner.RunnerException;
11+
12+
import java.io.ByteArrayOutputStream;
13+
import java.io.IOException;
14+
import java.util.concurrent.TimeUnit;
15+
16+
/*
17+
Benchmark Mode Cnt Score Error Units
18+
SerPb.ser avgt 5 143346.157 ± 8530.555 ns/op
19+
*/
20+
@State(Scope.Thread)
21+
public class SerPb {
22+
23+
private Pb.PbTestObject testObject;
24+
private ByteArrayOutputStream byteArrayOutputStream;
25+
26+
@Setup(Level.Trial)
27+
public void benchSetup(BenchmarkParams params) {
28+
testObject = Pb.PbTestObject.newBuilder()
29+
.setField1(31.415926)
30+
.setField2(61.415923)
31+
.setField3(31.415269)
32+
.setField4(53.141926)
33+
.setField5(13.145926)
34+
.setField6(43.115926)
35+
.setField7(31.419265)
36+
.setField8(23.141596)
37+
.setField9(43.161592)
38+
.setField10(0.112)
39+
.build();
40+
byteArrayOutputStream = new ByteArrayOutputStream();
41+
}
42+
43+
@Benchmark
44+
@BenchmarkMode(Mode.AverageTime)
45+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
46+
public void ser(Blackhole bh) throws IOException {
47+
for (int i = 0; i < 1000; i++) {
48+
byteArrayOutputStream.reset();
49+
testObject.writeTo(byteArrayOutputStream);
50+
bh.consume(byteArrayOutputStream);
51+
}
52+
}
53+
54+
@Test
55+
public void test() throws InvalidProtocolBufferException {
56+
// benchSetup(null);
57+
// Pb.PbTestObject parsed = Pb.PbTestObject.parseFrom(testData);
58+
// System.out.println(parsed.getField1());
59+
}
60+
61+
public static void main(String[] args) throws IOException, RunnerException {
62+
All.loadJMH();
63+
Main.main(new String[]{
64+
"with_10_double_fields.SerPb",
65+
"-i", "5",
66+
"-wi", "5",
67+
"-f", "1",
68+
});
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.jsoniter.benchmark.with_10_double_fields;
2+
3+
import com.jsoniter.benchmark.All;
4+
import org.apache.thrift.TException;
5+
import org.apache.thrift.TSerializer;
6+
import org.apache.thrift.protocol.TCompactProtocol;
7+
import org.apache.thrift.protocol.TProtocol;
8+
import org.apache.thrift.transport.TIOStreamTransport;
9+
import org.junit.Test;
10+
import org.openjdk.jmh.Main;
11+
import org.openjdk.jmh.annotations.*;
12+
import org.openjdk.jmh.infra.BenchmarkParams;
13+
import org.openjdk.jmh.infra.Blackhole;
14+
import org.openjdk.jmh.runner.RunnerException;
15+
16+
import java.io.ByteArrayOutputStream;
17+
import java.io.IOException;
18+
19+
/*
20+
Benchmark Mode Cnt Score Error Units
21+
SerThrift.ser thrpt 5 2093533.015 ± 61061.517 ops/s
22+
*/
23+
@State(Scope.Thread)
24+
public class SerThrift {
25+
26+
private ThriftTestObject testObject;
27+
private ByteArrayOutputStream byteArrayOutputStream;
28+
private TProtocol protocol;
29+
30+
@Setup(Level.Trial)
31+
public void benchSetup(BenchmarkParams params) throws TException {
32+
testObject = new ThriftTestObject();
33+
testObject.setField1(31.415926);
34+
testObject.setField2(61.415923);
35+
testObject.setField3(31.415269);
36+
testObject.setField4(53.141926);
37+
testObject.setField5(13.145926);
38+
testObject.setField6(43.115926);
39+
testObject.setField7(31.419265);
40+
testObject.setField8(23.141596);
41+
testObject.setField9(43.161592);
42+
testObject.setField10(0.112);
43+
byteArrayOutputStream = new ByteArrayOutputStream();
44+
TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory();
45+
protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream));
46+
}
47+
48+
@Test
49+
public void test() throws TException {
50+
byte[] output = new TSerializer(new TCompactProtocol.Factory()).serialize(testObject);
51+
System.out.println(output.length);
52+
}
53+
54+
@Benchmark
55+
public void ser(Blackhole bh) throws TException {
56+
byteArrayOutputStream.reset();
57+
testObject.write(protocol);
58+
bh.consume(byteArrayOutputStream);
59+
}
60+
61+
public static void main(String[] args) throws IOException, RunnerException {
62+
All.loadJMH();
63+
Main.main(new String[]{
64+
"with_10_double_fields.SerThrift",
65+
"-i", "5",
66+
"-wi", "5",
67+
"-f", "1",
68+
});
69+
}
70+
}

Diff for: src/main/java/com/jsoniter/benchmark/with_10_int_fields/DeserDslJson.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,8 @@
1313
import java.util.concurrent.TimeUnit;
1414

1515
/*
16-
Benchmark Mode Cnt Score Error Units
17-
DeserDslJson.deser avgt 5 9447.979 ± 874.721 ns/op (3.09x)
18-
19-
55,809,370,771 cycles (66.77%)
20-
144,924,278,921 instructions # 2.60 insns per cycle (83.44%)
21-
363,662,713 cache-references (83.34%)
22-
71,799,007 cache-misses # 19.743 % of all cache refs (83.40%)
23-
43,652 page-faults
24-
27,459,174,370 branches (83.30%)
25-
130,971,965 branch-misses # 0.48% of all branches (83.31%)
26-
27-
15.870780459 seconds time elapsed
16+
Benchmark Mode Cnt Score Error Units
17+
DeserDslJson.deser avgt 5 422839.151 ± 6216.061 ns/op
2818
*/
2919
@State(Scope.Thread)
3020
public class DeserDslJson {

Diff for: src/main/java/com/jsoniter/benchmark/with_10_int_fields/DeserJackson.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import java.util.concurrent.TimeUnit;
1515

1616
/*
17-
Benchmark Mode Cnt Score Error Units
18-
DeserJackson.deser avgt 5 612888.557 ± 35348.528 ns/op
17+
Benchmark Mode Cnt Score Error Units
18+
DeserJackson.deser avgt 5 604894.752 ± 3315.567 ns/op
1919
*/
2020
@State(Scope.Thread)
2121
public class DeserJackson {

Diff for: src/main/java/com/jsoniter/benchmark/with_10_int_fields/DeserJsoniter.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/*
2222
Benchmark Mode Cnt Score Error Units
23-
DeserJsoniter.deser avgt 5 278299.690 ± 9287.511 ns/op
23+
DeserJsoniter.deser avgt 5 187654.012 ± 1685.110 ns/op
2424
*/
2525
@State(Scope.Thread)
2626
public class DeserJsoniter {
@@ -51,8 +51,9 @@ public void deser(Blackhole bh) throws IOException {
5151
@Test
5252
public void test() throws IOException {
5353
benchSetup(null);
54+
System.out.println(new String(testJSON));
5455
iter.reset(testJSON);
55-
assertEquals("", iter.read(typeLiteral).field1);
56+
assertEquals(31415926, iter.read(typeLiteral).field1);
5657
}
5758

5859
public static void main(String[] args) throws IOException, RunnerException {

Diff for: src/main/java/com/jsoniter/benchmark/with_10_int_fields/DeserPb.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
/*
1616
Benchmark Mode Cnt Score Error Units
17-
DeserPb.deser avgt 5 83348.992 ± 4892.105 ns/op
17+
DeserPb.deser avgt 5 71067.990 ± 2736.220 ns/op
1818
*/
1919
@State(Scope.Thread)
2020
public class DeserPb {

Diff for: src/main/java/com/jsoniter/benchmark/with_10_int_fields/DeserThrift.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/*
1919
Benchmark Mode Cnt Score Error Units
20-
DeserThrift.deser avgt 5 201031.552 ± 5668.831 ns/op
20+
DeserThrift.deser avgt 5 202921.616 ± 2402.650 ns/op
2121
*/
2222
@State(Scope.Thread)
2323
public class DeserThrift {

0 commit comments

Comments
 (0)