Skip to content

Commit

Permalink
Add benchmarks for simdjson-java
Browse files Browse the repository at this point in the history
  • Loading branch information
plokhotnyuk committed Oct 27, 2024
1 parent a003b18 commit a33af2b
Show file tree
Hide file tree
Showing 25 changed files with 360 additions and 3 deletions.
3 changes: 3 additions & 0 deletions benchmark-jsoniter-scala-vs-simdjson-java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
sbt -java-home /usr/lib/jvm/jdk-24 ++3.6.1 jsoniter-scala-benchmarkJVM/clean 'jsoniter-scala-benchmarkJVM/jmh:run -p size=1,10,100,1000,10000,100000,1000000 (ArrayOf(Boolean|Byte|Double|Float|Int|Long|Short)s|StringOf(Ascii|Escaped|NonAscii)Chars)Reading.(jsoniterScala|simdjsonJava)' 2>&1 | tee jsoniter-scala-vs-simdjson-java.txt
sbt -java-home /usr/lib/jvm/jdk-24 ++3.6.1 jsoniter-scala-benchmarkJVM/clean 'jsoniter-scala-benchmarkJVM/jmh:run -t 16 -p size=1,10,100,1000,10000,100000,1000000 (ArrayOf(Boolean|Byte|Double|Float|Int|Long|Short)s|StringOf(Ascii|Escaped|NonAscii)Chars)Reading.(jsoniterScala|simdjsonJava)' 2>&1 | tee jsoniter-scala-vs-simdjson-java-t16.txt
5 changes: 5 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ lazy val `jsoniter-scala-benchmark` = crossProject(JVMPlatform, JSPlatform)
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.18.0",
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.18.0",
"com.fasterxml.jackson.module" % "jackson-module-blackbird" % "2.18.0",
"org.simdjson" % "simdjson-java" % "0.3.0",
"org.openjdk.jmh" % "jmh-core" % "1.37",
"org.openjdk.jmh" % "jmh-generator-asm" % "1.37",
"org.openjdk.jmh" % "jmh-generator-bytecode" % "1.37",
Expand All @@ -276,6 +277,10 @@ lazy val `jsoniter-scala-benchmark` = crossProject(JVMPlatform, JSPlatform)

lazy val `jsoniter-scala-benchmarkJVM` = `jsoniter-scala-benchmark`.jvm
.enablePlugins(JmhPlugin)
.settings(
Test / fork := true,
Test / javaOptions ++= Seq("--add-modules", "jdk.incubator.vector")
)

lazy val assemblyJSBenchmarks = sys.props.get("assemblyJSBenchmarks").isDefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ArrayOfBooleansReadingSpec extends BenchmarkSpecBase {
benchmark.jsoniterScala() shouldBe benchmark.obj
benchmark.playJson() shouldBe benchmark.obj
benchmark.playJsonJsoniter() shouldBe benchmark.obj
benchmark.simdjsonJava() shouldBe benchmark.obj
benchmark.smithy4sJson() shouldBe benchmark.obj
benchmark.sprayJson() shouldBe benchmark.obj
benchmark.uPickle() shouldBe benchmark.obj
Expand All @@ -36,6 +37,7 @@ class ArrayOfBooleansReadingSpec extends BenchmarkSpecBase {
intercept[Throwable](b.jsoniterScala())
intercept[Throwable](b.playJson())
intercept[Throwable](b.playJsonJsoniter())
intercept[Throwable](b.simdjsonJava())
intercept[Throwable](b.smithy4sJson())
intercept[Throwable](b.sprayJson())
intercept[Throwable](b.uPickle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ArrayOfBytesReadingSpec extends BenchmarkSpecBase {
benchmark.jsoniterScala() shouldBe benchmark.obj
benchmark.playJson() shouldBe benchmark.obj
benchmark.playJsonJsoniter() shouldBe benchmark.obj
benchmark.simdjsonJava() shouldBe benchmark.obj
benchmark.smithy4sJson() shouldBe benchmark.obj
benchmark.sprayJson() shouldBe benchmark.obj
benchmark.uPickle() shouldBe benchmark.obj
Expand All @@ -36,6 +37,7 @@ class ArrayOfBytesReadingSpec extends BenchmarkSpecBase {
intercept[Throwable](b.jsoniterScala())
intercept[Throwable](b.playJson())
intercept[Throwable](b.playJsonJsoniter())
intercept[Throwable](b.simdjsonJava())
intercept[Throwable](b.smithy4sJson())
intercept[Throwable](b.sprayJson())
intercept[Throwable](b.uPickle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ArrayOfDoublesReadingSpec extends BenchmarkSpecBase {
benchmark.jsoniterScala() shouldBe benchmark.obj
benchmark.playJson() shouldBe benchmark.obj
benchmark.playJsonJsoniter() shouldBe benchmark.obj
benchmark.simdjsonJava() shouldBe benchmark.obj
benchmark.smithy4sJson() shouldBe benchmark.obj
benchmark.sprayJson() shouldBe benchmark.obj
benchmark.uPickle() shouldBe benchmark.obj
Expand All @@ -36,6 +37,7 @@ class ArrayOfDoublesReadingSpec extends BenchmarkSpecBase {
intercept[Throwable](b.jsoniterScala())
intercept[Throwable](b.playJson())
intercept[Throwable](b.playJsonJsoniter())
intercept[Throwable](b.simdjsonJava())
intercept[Throwable](b.smithy4sJson())
intercept[Throwable](b.sprayJson())
intercept[Throwable](b.uPickle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ArrayOfFloatsReadingSpec extends BenchmarkSpecBase {
benchmark.jsoniterScala() shouldBe benchmark.obj
benchmark.playJson() shouldBe benchmark.obj
benchmark.playJsonJsoniter() shouldBe benchmark.obj
benchmark.simdjsonJava() shouldBe benchmark.obj
benchmark.smithy4sJson() shouldBe benchmark.obj
benchmark.sprayJson() shouldBe benchmark.obj
benchmark.uPickle() shouldBe benchmark.obj
Expand All @@ -47,6 +48,7 @@ class ArrayOfFloatsReadingSpec extends BenchmarkSpecBase {
intercept[Throwable](b.jsoniterScala())
intercept[Throwable](b.playJson())
intercept[Throwable](b.playJsonJsoniter())
intercept[Throwable](b.simdjsonJava())
intercept[Throwable](b.smithy4sJson())
intercept[Throwable](b.sprayJson())
intercept[Throwable](b.uPickle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ArrayOfIntsReadingSpec extends BenchmarkSpecBase {
benchmark.jsoniterScala() shouldBe benchmark.obj
benchmark.playJson() shouldBe benchmark.obj
benchmark.playJsonJsoniter() shouldBe benchmark.obj
benchmark.simdjsonJava() shouldBe benchmark.obj
benchmark.smithy4sJson() shouldBe benchmark.obj
benchmark.sprayJson() shouldBe benchmark.obj
benchmark.uPickle() shouldBe benchmark.obj
Expand All @@ -36,6 +37,7 @@ class ArrayOfIntsReadingSpec extends BenchmarkSpecBase {
intercept[Throwable](b.jsoniterScala())
intercept[Throwable](b.playJson())
intercept[Throwable](b.playJsonJsoniter())
intercept[Throwable](b.simdjsonJava())
intercept[Throwable](b.smithy4sJson())
intercept[Throwable](b.sprayJson())
intercept[Throwable](b.uPickle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ArrayOfLongsReadingSpec extends BenchmarkSpecBase {
benchmark.jsoniterScala() shouldBe benchmark.obj
benchmark.playJson() shouldBe benchmark.obj
benchmark.playJsonJsoniter() shouldBe benchmark.obj
benchmark.simdjsonJava() shouldBe benchmark.obj
benchmark.smithy4sJson() shouldBe benchmark.obj
benchmark.sprayJson() shouldBe benchmark.obj
benchmark.uPickle() shouldBe benchmark.obj
Expand All @@ -36,6 +37,7 @@ class ArrayOfLongsReadingSpec extends BenchmarkSpecBase {
intercept[Throwable](b.jsoniterScala())
intercept[Throwable](b.playJson())
intercept[Throwable](b.playJsonJsoniter())
intercept[Throwable](b.simdjsonJava())
intercept[Throwable](b.smithy4sJson())
intercept[Throwable](b.sprayJson())
intercept[Throwable](b.uPickle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ArrayOfShortsReadingSpec extends BenchmarkSpecBase {
benchmark.jsoniterScala() shouldBe benchmark.obj
benchmark.playJson() shouldBe benchmark.obj
benchmark.playJsonJsoniter() shouldBe benchmark.obj
benchmark.simdjsonJava() shouldBe benchmark.obj
benchmark.smithy4sJson() shouldBe benchmark.obj
benchmark.sprayJson() shouldBe benchmark.obj
benchmark.uPickle() shouldBe benchmark.obj
Expand All @@ -36,6 +37,7 @@ class ArrayOfShortsReadingSpec extends BenchmarkSpecBase {
intercept[Throwable](b.jsoniterScala())
intercept[Throwable](b.playJson())
intercept[Throwable](b.playJsonJsoniter())
intercept[Throwable](b.simdjsonJava())
intercept[Throwable](b.smithy4sJson())
intercept[Throwable](b.sprayJson())
intercept[Throwable](b.uPickle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class StringOfAsciiCharsReadingSpec extends BenchmarkSpecBase {
benchmark.jsoniterScala() shouldBe benchmark.obj
benchmark.playJson() shouldBe benchmark.obj
benchmark.playJsonJsoniter() shouldBe benchmark.obj
benchmark.simdjsonJava() shouldBe benchmark.obj
benchmark.smithy4sJson() shouldBe benchmark.obj
benchmark.sprayJson() shouldBe benchmark.obj
benchmark.uPickle() shouldBe benchmark.obj
Expand All @@ -38,6 +39,7 @@ class StringOfAsciiCharsReadingSpec extends BenchmarkSpecBase {
intercept[Throwable](b.jsoniterScala())
intercept[Throwable](b.playJson())
intercept[Throwable](b.playJsonJsoniter())
intercept[Throwable](b.simdjsonJava())
intercept[Throwable](b.smithy4sJson())
intercept[Throwable](b.sprayJson())
intercept[Throwable](b.uPickle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class StringOfEscapedCharsReadingSpec extends BenchmarkSpecBase {
benchmark.jsoniterScala() shouldBe benchmark.obj
benchmark.playJson() shouldBe benchmark.obj
benchmark.playJsonJsoniter() shouldBe benchmark.obj
benchmark.simdjsonJava() shouldBe benchmark.obj
benchmark.smithy4sJson() shouldBe benchmark.obj
benchmark.sprayJson() shouldBe benchmark.obj
benchmark.uPickle() shouldBe benchmark.obj
Expand All @@ -38,6 +39,7 @@ class StringOfEscapedCharsReadingSpec extends BenchmarkSpecBase {
intercept[Throwable](b.jsoniterScala())
intercept[Throwable](b.playJson())
intercept[Throwable](b.playJsonJsoniter())
intercept[Throwable](b.simdjsonJava())
intercept[Throwable](b.smithy4sJson())
intercept[Throwable](b.sprayJson())
intercept[Throwable](b.uPickle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class StringOfNonAsciiCharsReadingSpec extends BenchmarkSpecBase {
benchmark.jsoniterScala() shouldBe benchmark.obj
benchmark.playJson() shouldBe benchmark.obj
benchmark.playJsonJsoniter() shouldBe benchmark.obj
benchmark.simdjsonJava() shouldBe benchmark.obj
benchmark.smithy4sJson() shouldBe benchmark.obj
benchmark.sprayJson() shouldBe benchmark.obj
benchmark.uPickle() shouldBe benchmark.obj
Expand All @@ -38,6 +39,7 @@ class StringOfNonAsciiCharsReadingSpec extends BenchmarkSpecBase {
intercept[Throwable](b.jsoniterScala())
intercept[Throwable](b.playJson())
intercept[Throwable](b.playJsonJsoniter())
intercept[Throwable](b.simdjsonJava())
intercept[Throwable](b.smithy4sJson())
intercept[Throwable](b.sprayJson())
intercept[Throwable](b.uPickle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class ArrayOfBooleansReading extends ArrayOfBooleansBenchmark {
readFromArray(jsonBytes).as[Array[Boolean]]
}

@Benchmark
def simdjsonJava(): Array[Boolean] =
simdJsonParser.get.parse[Array[Boolean]](jsonBytes, jsonBytes.length, classOf[Array[Boolean]])

@Benchmark
def smithy4sJson(): Array[Boolean] = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.Smithy4sJCodecs._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class ArrayOfBytesReading extends ArrayOfBytesBenchmark {
readFromArray(jsonBytes).as[Array[Byte]]
}

@Benchmark
def simdjsonJava(): Array[Byte] =
simdJsonParser.get.parse[Array[Byte]](jsonBytes, jsonBytes.length, classOf[Array[Byte]])

@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 @@ -78,6 +78,10 @@ class ArrayOfDoublesReading extends ArrayOfDoublesBenchmark {
readFromArray(jsonBytes).as[Array[Double]]
}

@Benchmark
def simdjsonJava(): Array[Double] =
simdJsonParser.get.parse[Array[Double]](jsonBytes, jsonBytes.length, classOf[Array[Double]])

@Benchmark
def smithy4sJson(): Array[Double] = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.Smithy4sJCodecs._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class ArrayOfFloatsReading extends ArrayOfFloatsBenchmark {
readFromArray[play.api.libs.json.JsValue](jsonBytes).as[Array[Float]]
}

@Benchmark
def simdjsonJava(): Array[Float] =
simdJsonParser.get.parse[Array[Float]](jsonBytes, jsonBytes.length, classOf[Array[Float]])

@Benchmark
def smithy4sJson(): Array[Float] = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.Smithy4sJCodecs._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class ArrayOfIntsReading extends ArrayOfIntsBenchmark {
readFromArray(jsonBytes).as[Array[Int]]
}

@Benchmark
def simdjsonJava(): Array[Int] =
simdJsonParser.get.parse[Array[Int]](jsonBytes, jsonBytes.length, classOf[Array[Int]])

@Benchmark
def smithy4sJson(): Array[Int] = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.Smithy4sJCodecs._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class ArrayOfLongsReading extends ArrayOfLongsBenchmark {
readFromArray(jsonBytes).as[Array[Long]]
}

@Benchmark
def simdjsonJava(): Array[Long] =
simdJsonParser.get.parse[Array[Long]](jsonBytes, jsonBytes.length, classOf[Array[Long]])

@Benchmark
def smithy4sJson(): Array[Long] = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.Smithy4sJCodecs._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class ArrayOfShortsReading extends ArrayOfShortsBenchmark {
readFromArray[play.api.libs.json.JsValue](jsonBytes).as[Array[Short]]
}

@Benchmark
def simdjsonJava(): Array[Short] =
simdJsonParser.get.parse[Array[Short]](jsonBytes, jsonBytes.length, classOf[Array[Short]])

@Benchmark
def smithy4sJson(): Array[Short] = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.Smithy4sJCodecs._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class StringOfAsciiCharsReading extends StringOfAsciiCharsBenchmark {
readFromArray[play.api.libs.json.JsValue](jsonBytes, tooLongStringConfig).as[String]
}

@Benchmark
def simdjsonJava(): String =
simdJsonParser.get.parse[String](jsonBytes, jsonBytes.length, classOf[String])

@Benchmark
def smithy4sJson(): String = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.Smithy4sJCodecs._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class StringOfEscapedCharsReading extends StringOfEscapedCharsBenchmark {
readFromArray[play.api.libs.json.JsValue](jsonBytes, tooLongStringConfig).as[String]
}

@Benchmark
def simdjsonJava(): String =
simdJsonParser.get.parse[String](jsonBytes, jsonBytes.length, classOf[String])

@Benchmark
def smithy4sJson(): String = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.Smithy4sJCodecs._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class StringOfNonAsciiCharsReading extends StringOfNonAsciiCharsBenchmark {
readFromArray[play.api.libs.json.JsValue](jsonBytes, tooLongStringConfig).as[String]
}

@Benchmark
def simdjsonJava(): String =
simdJsonParser.get.parse[String](jsonBytes, jsonBytes.length, classOf[String])

@Benchmark
def smithy4sJson(): String = {
import com.github.plokhotnyuk.jsoniter_scala.benchmark.Smithy4sJCodecs._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package com.github.plokhotnyuk.jsoniter_scala.benchmark

import java.util.concurrent.TimeUnit
import org.openjdk.jmh.annotations._
import org.simdjson.SimdJsonParser

@State(Scope.Thread)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(value = 1, jvmArgs = Array(
// "-Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false",
// "-XX:+UseTransparentHugePages",
"--add-modules",
"jdk.incubator.vector",
"-server",
"-noclassgc",
"-Xms2g",
"-Xmx2g",
"-Xms16g",
"-Xmx16g",
"-XX:NewSize=1g",
"-XX:MaxNewSize=1g",
"-XX:InitialCodeCacheSize=512m",
Expand All @@ -39,4 +42,8 @@ import org.openjdk.jmh.annotations._
))
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
abstract class CommonParams
abstract class CommonParams {
val simdJsonParser: ThreadLocal[SimdJsonParser] = new ThreadLocal[SimdJsonParser] {
override def initialValue(): SimdJsonParser = new SimdJsonParser
}
}
Loading

0 comments on commit a33af2b

Please sign in to comment.