-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
TwitterAPIBenchmark.scala
80 lines (68 loc) · 3.06 KB
/
TwitterAPIBenchmark.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
73
74
75
76
77
78
79
80
package com.github.plokhotnyuk.jsoniter_scala.benchmark
import java.nio.charset.StandardCharsets.UTF_8
import com.avsystem.commons.serialization.json._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.AVSystemCodecs._
//import com.github.plokhotnyuk.jsoniter_scala.benchmark.DslPlatformJson._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.JacksonSerDesers._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.JsoniterScalaCodecs._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.PlayJsonFormats._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.TwitterAPI._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.SprayFormats._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.UPickleReaderWriters._
import com.github.plokhotnyuk.jsoniter_scala.core._
import io.circe.generic.auto._
import io.circe.parser._
//import io.circe.syntax._
import org.openjdk.jmh.annotations.Benchmark
import play.api.libs.json.Json
import spray.json._
class TwitterAPIBenchmark extends CommonParams {
var obj: Seq[Tweet] = readFromArray[Seq[Tweet]](jsonBytes)
var preallocatedBuf: Array[Byte] = new Array(compactJsonBytes.length + 100/*to avoid possible out of bounds error*/)
@Benchmark
def readAVSystemGenCodec(): Seq[Tweet] = JsonStringInput.read[Seq[Tweet]](new String(jsonBytes, UTF_8))
@Benchmark
def readCirce(): Seq[Tweet] = decode[Seq[Tweet]](new String(jsonBytes, UTF_8)).fold(throw _, identity)
/* FIXME: DSL_JSON throws java.lang.IllegalArgumentException: argument type mismatch
@Benchmark
def readDslJsonScala(): Seq[Tweet] = dslJsonDecode[Seq[Tweet]](jsonBytes)
*/
@Benchmark
def readJacksonScala(): Seq[Tweet] = jacksonMapper.readValue[Seq[Tweet]](jsonBytes)
@Benchmark
def readJsoniterScala(): Seq[Tweet] = readFromArray[Seq[Tweet]](jsonBytes)
@Benchmark
def readPlayJson(): Seq[Tweet] = Json.parse(jsonBytes).as[Seq[Tweet]]
@Benchmark
def readSprayJson(): Seq[Tweet] = JsonParser(jsonBytes).convertTo[Seq[Tweet]]
@Benchmark
def readUPickle(): Seq[Tweet] = read[Seq[Tweet]](jsonBytes)
@Benchmark
def writeAVSystemGenCodec(): Array[Byte] = JsonStringOutput.write(obj).getBytes(UTF_8)
/* FIXME: circe serializes empty collections
@Benchmark
def writeCirce(): Array[Byte] = printer.pretty(obj.asJson).getBytes(UTF_8)
*/
/* FIXME: DSL-JSON serializes empty collections
@Benchmark
def writeDslJsonScala(): Array[Byte] = dslJsonEncode[Seq[Tweet]](obj)
*/
@Benchmark
def writeJacksonScala(): Array[Byte] = jacksonMapper.writeValueAsBytes(obj)
@Benchmark
def writeJsoniterScala(): Array[Byte] = writeToArray(obj)
@Benchmark
def writeJsoniterScalaPrealloc(): Int = writeToSubArray(obj, preallocatedBuf, 0, preallocatedBuf.length)
/* FIXME: Play-JSON serializes empty collections
@Benchmark
def writePlayJson(): Array[Byte] = Json.toBytes(Json.toJson(obj))
*/
/* FIXME: Spray-JSON serializes empty collections
@Benchmark
def writeSprayJson(): Array[Byte] = obj.toJson.compactPrint.getBytes(UTF_8)
*/
/* FIXME: uPickle serializes empty collections
@Benchmark
def writeUPickle(): Array[Byte] = write(obj).getBytes(UTF_8)
*/
}