-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathGithubIssuesJsonAST.scala
More file actions
57 lines (43 loc) · 1.49 KB
/
GithubIssuesJsonAST.scala
File metadata and controls
57 lines (43 loc) · 1.49 KB
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
package spray.json
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Param
import org.openjdk.jmh.annotations.Setup
import scala.io.Source
import play.api.libs.json.Json
class GithubIssuesJsonAST extends Common {
@Param(Array("github-akka-issues.json", "big-string-array.json"))
var res: String = null
var jsonString: String = _
var jsonBytes: Array[Byte] = _
var sprayJsonAST: JsValue = _
var playJsonAST: play.api.libs.json.JsValue = _
var upickleAST: ujson.Js.Value = _
var circeAST: io.circe.Json = _
@Setup
def setup(): Unit = {
jsonString = Source.fromResource(res).mkString
jsonBytes = jsonString.getBytes("utf8") // yeah, a useless utf8 roundtrip
sprayJsonAST = JsonParser(jsonString)
playJsonAST = Json.parse(jsonString)
upickleAST = ujson.read(jsonString)
circeAST = io.circe.parser.parse(jsonString).right.get
}
@Benchmark
def readSprayJsonFromString(): Unit = JsonParser(jsonString)
@Benchmark
def readSprayJsonFromBytes(): Unit = JsonParser(jsonBytes)
@Benchmark
def readPlayJson(): Unit = Json.parse(jsonString)
@Benchmark
def readUPickle(): Unit = ujson.read(jsonString)
@Benchmark
def readCirce(): Unit = io.circe.parser.parse(jsonString)
@Benchmark
def writeSprayJson(): Unit = sprayJsonAST.compactPrint
@Benchmark
def writePlayJson(): Unit = playJsonAST.toString()
@Benchmark
def writeUPickle(): Unit = ujson.write(upickleAST)
@Benchmark
def writeCirce(): Unit = circeAST.toString()
}