Skip to content

Commit

Permalink
Add Borer benchmarks for AnyVals
Browse files Browse the repository at this point in the history
  • Loading branch information
plokhotnyuk committed May 11, 2019
1 parent ac484d5 commit 7d9a386
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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.BorerJsonEncodersDecoders._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.CirceEncodersDecoders._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.JacksonSerDesers._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.JsoniterScalaCodecs._
Expand All @@ -20,6 +21,9 @@ class AnyValsReading extends AnyValsBenchmark {
@Benchmark
def avSystemGenCodec(): AnyVals = JsonStringInput.read[AnyVals](new String(jsonBytes, UTF_8))

@Benchmark
def borerJson(): AnyVals = io.bullet.borer.Json.decode(jsonBytes).to[AnyVals].value

@Benchmark
def circe(): AnyVals = decode[AnyVals](new String(jsonBytes, UTF_8)).fold(throw _, identity)
/* FIXME: DSL-JSON throws java.lang.IllegalArgumentException: requirement failed: Unable to create decoder for com.github.plokhotnyuk.jsoniter_scala.benchmark.AnyVals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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.BorerJsonEncodersDecoders._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.CirceEncodersDecoders._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.JacksonSerDesers._
import com.github.plokhotnyuk.jsoniter_scala.benchmark.JsoniterScalaCodecs._
Expand All @@ -20,6 +21,9 @@ class AnyValsWriting extends AnyValsBenchmark {
@Benchmark
def avSystemGenCodec(): Array[Byte] = JsonStringOutput.write(obj).getBytes(UTF_8)

@Benchmark
def borerJson(): Array[Byte] = io.bullet.borer.Json.encode(obj).toByteArray

@Benchmark
def circe(): Array[Byte] = printer.pretty(obj.asJson).getBytes(UTF_8)
/* FIXME: DSL-JSON throws java.lang.IllegalArgumentException: requirement failed: Unable to create decoder for com.github.plokhotnyuk.jsoniter_scala.benchmark.AnyVals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ object BorerJsonEncodersDecoders {
Decoder.forJBigInteger(maxJsonNumberStringLength = 1000000).map(x => new BigInt(x)) /*WARNING: don't do this for open-systems*/
implicit val bigDecimalDec: Decoder[BigDecimal] =
Decoder.forJBigDecimal(maxJsonNumberStringLength = 1000000).map(x => new BigDecimal(x, MathContext.UNLIMITED)) /*WARNING: don't do this for open-systems*/
implicit val Codec(anyRefsEnc: Encoder[AnyRefs], anyRefsDec: Decoder[AnyRefs]) = deriveCodec[AnyRefs]
implicit val Codec(charEnc: Encoder[Char], charDec: Decoder[Char]) = stringCodec(_.charAt(0))
implicit val Codec(anyValsEnc: Encoder[AnyVals], anyValsDec: Decoder[AnyVals]) = {
implicit val c1: Codec[ByteVal] = Codec(Encoder.forCaseClass[ByteVal], Decoder.forCaseClass[ByteVal])
implicit val c2: Codec[ShortVal] = Codec(Encoder.forCaseClass[ShortVal], Decoder.forCaseClass[ShortVal])
implicit val c3: Codec[IntVal] = Codec(Encoder.forCaseClass[IntVal], Decoder.forCaseClass[IntVal])
implicit val c4: Codec[LongVal] = Codec(Encoder.forCaseClass[LongVal], Decoder.forCaseClass[LongVal])
implicit val c5: Codec[BooleanVal] = Codec(Encoder.forCaseClass[BooleanVal], Decoder.forCaseClass[BooleanVal])
implicit val c6: Codec[CharVal] = Codec(Encoder.forCaseClass[CharVal], Decoder.forCaseClass[CharVal])
implicit val c7: Codec[DoubleVal] = Codec(Encoder.forCaseClass[DoubleVal], Decoder.forCaseClass[DoubleVal])
implicit val c8: Codec[FloatVal] = Codec(Encoder.forCaseClass[FloatVal], Decoder.forCaseClass[FloatVal])
deriveCodec[AnyVals]
}
implicit val Codec(anyRefsEnc: Encoder[AnyRefs], anyRefsDec: Decoder[AnyRefs]) = deriveCodec[AnyRefs]
implicit val Codec(extractFieldsEnc: Encoder[ExtractFields], extractFieldsDec: Decoder[ExtractFields]) =
deriveCodec[ExtractFields]
implicit val Codec(googleMapsAPIEnc: Encoder[DistanceMatrix], googleMapsAPIDec: Decoder[DistanceMatrix]) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class AnyValsReadingSpec extends BenchmarkSpecBase {
"AnyValsReading" should {
"read properly" in {
benchmark.avSystemGenCodec() shouldBe benchmark.obj
benchmark.borerJson() shouldBe benchmark.obj
benchmark.circe() shouldBe benchmark.obj
//FIXME: DSL-JSON throws java.lang.IllegalArgumentException: requirement failed: Unable to create decoder for com.github.plokhotnyuk.jsoniter_scala.benchmark.AnyVals
//benchmark.dslJsonScala() shouldBe benchmark.obj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class AnyValsWritingSpec extends BenchmarkSpecBase {
"AnyValsWriting" should {
"write properly" in {
toString(benchmark.avSystemGenCodec()) shouldBe benchmark.jsonString1
toString(benchmark.borerJson()) shouldBe benchmark.jsonString1
toString(benchmark.circe()) shouldBe benchmark.jsonString1
//FIXME: DSL-JSON throws java.lang.IllegalArgumentException: requirement failed: Unable to create decoder for com.github.plokhotnyuk.jsoniter_scala.benchmark.AnyVals
//toString(benchmark.dslJsonScala()) shouldBe benchmark.jsonString1
Expand Down

0 comments on commit 7d9a386

Please sign in to comment.