Skip to content

Commit

Permalink
Add GitHub Actions API benchmarks for play-json and play-json-jsoniter
Browse files Browse the repository at this point in the history
  • Loading branch information
plokhotnyuk committed Sep 6, 2022
1 parent 423e0e8 commit fd74b3e
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,8 @@ object Main {
B("circe")(benchmark.circe()),
B("circeJawn")(benchmark.circeJawn()),
B("circeJsoniter")(benchmark.circeJsoniter()),
B("playJson")(benchmark.playJson()),
B("playJsonJsoniter")(benchmark.playJsonJsoniter()),
B("jsoniterScala")(benchmark.jsoniterScala()),
B("smithy4sJson")(benchmark.smithy4sJson()),
B("uPickle")(benchmark.uPickle()),
Expand All @@ -1127,6 +1129,8 @@ object Main {
B("circeJsoniter")(benchmark.circeJsoniter()),
B("jsoniterScala")(benchmark.jsoniterScala()),
B("jsoniterScalaPrealloc")(benchmark.jsoniterScalaPrealloc()),
B("playJson")(benchmark.playJson()),
B("playJsonJsoniter")(benchmark.playJsonJsoniter()),
B("smithy4sJson")(benchmark.smithy4sJson()),
B("uPickle")(benchmark.uPickle()),
B("zioJson")(benchmark.zioJson())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class GitHubActionsAPIReadingSpec extends BenchmarkSpecBase {
benchmark.circeJawn() shouldBe benchmark.obj
benchmark.circeJsoniter() shouldBe benchmark.obj
benchmark.jsoniterScala() shouldBe benchmark.obj
benchmark.playJson() shouldBe benchmark.obj
benchmark.playJsonJsoniter() shouldBe benchmark.obj
benchmark.smithy4sJson() shouldBe benchmark.obj
benchmark.uPickle() shouldBe benchmark.obj
benchmark.zioJson() shouldBe benchmark.obj
Expand All @@ -24,6 +26,8 @@ class GitHubActionsAPIReadingSpec extends BenchmarkSpecBase {
intercept[Throwable](b.circeJawn())
intercept[Throwable](b.circeJsoniter())
intercept[Throwable](b.jsoniterScala())
intercept[Throwable](b.playJson())
intercept[Throwable](b.playJsonJsoniter())
intercept[Throwable](b.smithy4sJson())
intercept[Throwable](b.uPickle())
intercept[Throwable](b.zioJson())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class GitHubActionsAPIWritingSpec extends BenchmarkSpecBase {
toString(b.circeJsoniter()) shouldBe b.compactJsonString1
toString(b.jsoniterScala()) shouldBe b.compactJsonString1
toString(b.preallocatedBuf, 0, b.jsoniterScalaPrealloc()) shouldBe b.compactJsonString1
toString(b.playJson()) shouldBe b.compactJsonString1
toString(b.playJsonJsoniter()) shouldBe b.compactJsonString1
toString(b.smithy4sJson()) shouldBe b.compactJsonString1
toString(b.uPickle()) shouldBe b.compactJsonString1
toString(b.zioJson()) shouldBe b.compactJsonString1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class GitHubActionsAPIReadingSpec extends BenchmarkSpecBase {
benchmark.circeJsoniter() shouldBe benchmark.obj
benchmark.jacksonScala() shouldBe benchmark.obj
benchmark.jsoniterScala() shouldBe benchmark.obj
benchmark.playJson() shouldBe benchmark.obj
benchmark.playJsonJsoniter() shouldBe benchmark.obj
benchmark.smithy4sJson() shouldBe benchmark.obj
benchmark.sprayJson() shouldBe benchmark.obj
benchmark.uPickle() shouldBe benchmark.obj
Expand All @@ -28,6 +30,8 @@ class GitHubActionsAPIReadingSpec extends BenchmarkSpecBase {
intercept[Throwable](b.circeJsoniter())
intercept[Throwable](b.jacksonScala())
intercept[Throwable](b.jsoniterScala())
intercept[Throwable](b.playJson())
intercept[Throwable](b.playJsonJsoniter())
intercept[Throwable](b.smithy4sJson())
intercept[Throwable](b.sprayJson())
intercept[Throwable](b.weePickle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class GitHubActionsAPIWritingSpec extends BenchmarkSpecBase {
toString(b.jacksonScala()) shouldBe b.compactJsonString1
toString(b.jsoniterScala()) shouldBe b.compactJsonString1
toString(b.preallocatedBuf, 0, b.jsoniterScalaPrealloc()) shouldBe b.compactJsonString1
toString(b.playJson()) shouldBe b.compactJsonString1
toString(b.playJsonJsoniter()) shouldBe b.compactJsonString1
toString(b.smithy4sJson()) shouldBe b.compactJsonString1
toString(b.sprayJson()) shouldBe b.compactJsonString2
toString(b.uPickle()) shouldBe b.compactJsonString1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ class GitHubActionsAPIReading extends GitHubActionsAPIBenchmark {
readFromArray[GitHubActionsAPI.Response](jsonBytes)
}

@Benchmark
def playJson(): GitHubActionsAPI.Response = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.PlayJsonFormats._
import play.api.libs.json.Json

Json.parse(jsonBytes).as[GitHubActionsAPI.Response]
}

@Benchmark
def playJsonJsoniter(): GitHubActionsAPI.Response = {
import com.evolutiongaming.jsonitertool.PlayJsonJsoniter._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.PlayJsonFormats._
import com.github.plokhotnyuk.jsoniter_scala.core._

readFromArray(jsonBytes).as[GitHubActionsAPI.Response]
}


@Benchmark
def smithy4sJson(): GitHubActionsAPI.Response = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.Smithy4sJCodecs._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ class GitHubActionsAPIWriting extends GitHubActionsAPIBenchmark {
writeToSubArray(obj, preallocatedBuf, 0, preallocatedBuf.length)
}

@Benchmark
def playJson(): Array[Byte] = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.PlayJsonFormats._
import play.api.libs.json.Json

Json.toBytes(Json.toJson(obj))
}

@Benchmark
def playJsonJsoniter(): Array[Byte] = {
import com.evolutiongaming.jsonitertool.PlayJsonJsoniter._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.PlayJsonFormats._
import com.github.plokhotnyuk.jsoniter_scala.core._
import play.api.libs.json.Json

writeToArray(Json.toJson(obj))
}

@Benchmark
def smithy4sJson(): Array[Byte] = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.Smithy4sJCodecs._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ object PlayJsonFormats {
implicit lazy val v13: Format[GeoJSON.GeoJSON] = flat.oformat((__ \ "type").format[String])
v13
}
implicit val gitHubActionsAPIFormat: Format[GitHubActionsAPI.Response] = {
implicit val v1: Format[Boolean] = stringFormat[Boolean]("boolean") { s =>
if (s == "true") true
else if (s == "false") false
else sys.error("")
}
implicit val v2: Format[GitHubActionsAPI.Artifact] = Jsonx.formatCaseClass
Json.format
}
implicit val googleMapsAPIFormat: Format[GoogleMapsAPI.DistanceMatrix] = {
implicit val v1: Format[GoogleMapsAPI.Value] = Json.format
implicit val v2: Format[GoogleMapsAPI.Elements] = Json.format
Expand Down

0 comments on commit fd74b3e

Please sign in to comment.