When decision about JSON library should be made because of performance, this benchmark can be helpful. Benchmarked libraries:
This project also demonstrates how to use these different JSON libraries to serialize/deserialize a Scala case class
.
Dataset and types (Bird and Place) are from this repo: scala-json-benchmark. For benchmark used jmh via sbt-jmh plugin. File birds.data contains 25000 lines. Each of line is serialized json of Bird
.
- Serialization benchmark is in SerializationBenchmark.scala. To run it use
jmh:run -i 5 -wi 5 -f1 -t1 .*SerializationBenchmark*
inSBT
- Deserialization benchmark is in DeserializationBenchmark.scala. To run it use
jmh:run -i 5 -wi 5 -f1 -t1 .*DeserializationBenchmark*
inSBT
- OS: macOS Sierra 10.12.6
- CPU: Intel Core i7 3.1 GHz
- Memory: 16 GB
- JVM: Java HotSpot(TM) 64-Bit Server VM, 25.181-b13
Library | Time, ms |
---|---|
jsoniter | 50.113 |
circe | 140.868 |
spray | 165.045 |
lift | 206.377 |
play-json | 261.774 |
Argonaut | 306.668 |
json4s | 385.766 |
Library | Time, ms |
---|---|
jsoniter | 78.070 |
circe | 130.938 |
spray | 180.159 |
lift | 220.421 |
Argonaut | 319.450 |
play-json | 357.515 |
json4s | 467.872 |
- OS: Microsoft Windows 10 Pro N x64 [Version 10.0.17134.590]
- CPU: AMD Ryzen 7 2700X Eight-Core Processor i7 3.7 GHz
- Memory: DDR4-3200 GHz 16 GB
- JVM: Java HotSpot(TM) 64-Bit Server VM, 25.201-b09
Library | Time, ms |
---|---|
jsoniter | 41.140 |
circe | 104.434 |
spray | 132.525 |
lift | 171.015 |
play-json | 215.128 |
Argonaut | 255.371 |
json4s | 310.488 |
Library | Time, ms |
---|---|
jsoniter | 68.833 |
circe | 117.592 |
spray | 155.961 |
lift | 220.304 |
Argonaut | 264.283 |
play-json | 342.450 |
json4s | 403.946 |