@@ -2,6 +2,7 @@ package com.avsystem.commons
2
2
package ser
3
3
4
4
import com .avsystem .commons .serialization .json .{JsonStringInput , JsonStringOutput }
5
+ import com .avsystem .commons .serialization .nativejs .{NativeJsonInput , NativeJsonOutput }
5
6
import io .circe .parser ._
6
7
import io .circe .syntax ._
7
8
import japgolly .scalajs .benchmark .gui .GuiSuite
@@ -10,62 +11,86 @@ import japgolly.scalajs.benchmark.{Benchmark, Suite}
10
11
object JsonBenchmarks {
11
12
val suite = GuiSuite (
12
13
Suite (" JSON serialization benchmarks" )(
13
- Benchmark (" Writing case class: GenCodec" ) {
14
+ Benchmark (" Writing case class: GenCodec, String Json format " ) {
14
15
JsonStringOutput .write(Something .Example )
15
16
},
17
+ Benchmark (" Writing case class: GenCodec, Native Json format" ) {
18
+ NativeJsonOutput .writeAsString(Something .Example )
19
+ },
16
20
Benchmark (" Writing case class: Circe" ) {
17
21
Something .Example .asJson.noSpaces
18
22
},
19
23
Benchmark (" Writing case class: uPickle" ) {
20
24
upickle.default.write(Something .Example )
21
25
},
22
- Benchmark (" Reading case class: GenCodec" ) {
26
+ Benchmark (" Reading case class: GenCodec, String Json format " ) {
23
27
JsonStringInput .read[Something ](Something .ExampleJsonString )
24
28
},
29
+ Benchmark (" Reading case class: GenCodec, Native Json format" ) {
30
+ NativeJsonInput .readString[Something ](Something .ExampleJsonString )
31
+ },
25
32
Benchmark (" Reading case class: Circe" ) {
26
33
decode[Something ](Something .ExampleJsonString ).fold(e => throw e, identity)
27
34
},
28
35
Benchmark (" Reading case class: uPickle" ) {
29
36
upickle.default.read[Something ](Something .ExampleJsonString )
30
37
},
31
38
32
- Benchmark (" Writing sealed hierarchy: GenCodec" ) {
39
+ Benchmark (" Writing sealed hierarchy: GenCodec, String Json format " ) {
33
40
JsonStringOutput .write(SealedStuff .ExampleList )
34
41
},
35
- Benchmark (" Writing sealed hierarchy: GenCodec (flat)" ) {
42
+ Benchmark (" Writing sealed hierarchy: GenCodec (flat), String Json format " ) {
36
43
JsonStringOutput .write(FlatSealedStuff .ExampleList )
37
44
},
45
+ Benchmark (" Writing sealed hierarchy: GenCodec, Native Json format" ) {
46
+ NativeJsonOutput .writeAsString(SealedStuff .ExampleList )
47
+ },
48
+ Benchmark (" Writing sealed hierarchy: GenCodec (flat), Native Json format" ) {
49
+ NativeJsonOutput .writeAsString(FlatSealedStuff .ExampleList )
50
+ },
38
51
Benchmark (" Writing sealed hierarchy: Circe" ) {
39
52
SealedStuff .ExampleList .asJson.noSpaces
40
53
},
41
54
Benchmark (" Writing sealed hierarchy: uPickle" ) {
42
55
upickle.default.write(SealedStuff .ExampleList )
43
56
},
44
- Benchmark (" Reading sealed hierarchy: GenCodec" ) {
57
+ Benchmark (" Reading sealed hierarchy: GenCodec, String Json format " ) {
45
58
JsonStringInput .read[List [SealedStuff ]](SealedStuff .ExampleJsonString )
46
59
},
47
- Benchmark (" Reading sealed hierarchy: GenCodec (flat)" ) {
60
+ Benchmark (" Reading sealed hierarchy: GenCodec (flat), String Json format " ) {
48
61
JsonStringInput .read[List [FlatSealedStuff ]](FlatSealedStuff .ExampleJsonString )
49
62
},
63
+ Benchmark (" Reading sealed hierarchy: GenCodec, Native Json format" ) {
64
+ NativeJsonInput .readString[List [SealedStuff ]](SealedStuff .ExampleJsonString )
65
+ },
66
+ Benchmark (" Reading sealed hierarchy: GenCodec (flat), Native Json format" ) {
67
+ NativeJsonInput .readString[List [FlatSealedStuff ]](FlatSealedStuff .ExampleJsonString )
68
+ },
50
69
Benchmark (" Reading sealed hierarchy: Circe" ) {
51
70
decode[List [SealedStuff ]](SealedStuff .ExampleJsonString ).fold(e => throw e, identity)
52
71
},
53
72
Benchmark (" Reading sealed hierarchy: uPickle" ) {
54
73
upickle.default.read[List [SealedStuff ]](SealedStuff .ExampleUpickleJsonString )
55
74
},
56
75
57
- Benchmark (" Writing foos: GenCodec" ) {
76
+ Benchmark (" Writing foos: GenCodec, String Json format " ) {
58
77
JsonStringOutput .write(Foo .ExampleMap )
59
78
},
79
+ Benchmark (" Writing foos: GenCodec, Native Json format" ) {
80
+ NativeJsonOutput .writeAsString(Foo .ExampleMap )
81
+ },
60
82
Benchmark (" Writing foos: Circe" ) {
61
83
Foo .ExampleMap .asJson.noSpaces
62
84
},
63
85
Benchmark (" Writing foos: uPickle" ) {
64
86
upickle.default.write(Foo .ExampleMap )
65
87
},
66
- Benchmark (" Reading foos: GenCodec" ) {
88
+ Benchmark (" Reading foos: GenCodec, String Json format " ) {
67
89
JsonStringInput .read[Map [String , Foo ]](Foo .ExampleJsonString )
68
90
},
91
+ Benchmark (" Reading foos: GenCodec with Native Json format" ) {
92
+ NativeJsonInput .readString[Map [String , Foo ]](Foo .ExampleJsonString )
93
+ },
69
94
Benchmark (" Reading foos: Circe" ) {
70
95
decode[Map [String , Foo ]](Foo .ExampleJsonString ).fold(e => throw e, identity)
71
96
},
0 commit comments