-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerializationBenchmark.scala
72 lines (61 loc) · 1.67 KB
/
SerializationBenchmark.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package benchmarks
import java.nio.charset.StandardCharsets
import marshallers._
import models.Bird
import scala.io.Source
import org.openjdk.jmh.annotations._
import java.util.concurrent.TimeUnit
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.MILLISECONDS)
class SerializationBenchmark{
import SerializationBenchmark._
@Benchmark
def Json4SMarshaller_toStr(): Int = {
val parser = new Json4SMarshaller
val strs = birds.map(parser.toStr)
strs.length
}
@Benchmark
def LiftMarshaller_toStr(): Int = {
val parser = new LiftMarshaller
val strs = birds.map(parser.toStr)
strs.length
}
@Benchmark
def PlayMarshaller_toStr(): Int = {
val parser = new PlayMarshaller
val strs = birds.map(parser.toStr)
strs.length
}
@Benchmark
def ArgonautMarshaller_toStr(): Int = {
val parser = new ArgonautMarshaller
val strs = birds.map(parser.toStr)
strs.length
}
@Benchmark
def SprayMarshaller_toStr(): Int = {
val parser = new SprayMarshaller
val strs = birds.map(parser.toStr)
strs.length
}
@Benchmark
def CirceMarshaller_toStr(): Int = {
val parser = new CirceMarshaller
val strs = birds.map(parser.toStr)
strs.length
}
@Benchmark
def JsoniterMarshaller_toStr(): Int = {
val parser = new JsoniterMarshaller
val strs = birds.map(parser.toStr)
strs.length
}
}
object SerializationBenchmark {
val tempParser = new CirceMarshaller
val birds: Array[Bird] = Source.fromInputStream(getClass.getClassLoader.getResourceAsStream("birds.data"), StandardCharsets.UTF_8.name())
.getLines().toArray
.map { jsonStr => tempParser.parse(jsonStr) }
}