Skip to content

Commit

Permalink
Don't define implicit codecs for supported types
Browse files Browse the repository at this point in the history
  • Loading branch information
plokhotnyuk committed Apr 1, 2018
1 parent 3e382cf commit 741af95
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IntBenchmark extends CommonParams {
def readJacksonScala(): Int = jacksonMapper.readValue[Int](jsonBytes)

@Benchmark
def readJsoniterScala(): Int = readFromArray[Int](jsonBytes)
def readJsoniterScala(): Int = readFromArray[Int](jsonBytes)(intCodec)

@Benchmark
def readPlayJson(): Int = Json.parse(jsonBytes).as[Int]
Expand All @@ -41,10 +41,10 @@ class IntBenchmark extends CommonParams {
def writeJacksonScala(): Array[Byte] = jacksonMapper.writeValueAsBytes(obj)

@Benchmark
def writeJsoniterScala(): Array[Byte] = writeToArray(obj)
def writeJsoniterScala(): Array[Byte] = writeToArray(obj)(intCodec)

@Benchmark
def writeJsoniterScalaPrealloc(): Int = writeToPreallocatedArray(obj, preallocatedBuf, 0)
def writeJsoniterScalaPrealloc(): Int = writeToPreallocatedArray(obj, preallocatedBuf, 0)(intCodec)

@Benchmark
def writePlayJson(): Array[Byte] = Json.toBytes(Json.toJson(obj))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ object JsoniterCodecs {
val stacklessExceptionConfig = ReaderConfig(throwParseExceptionWithStackTrace = false)
val stacklessExceptionWithoutDumpConfig =
ReaderConfig(throwParseExceptionWithStackTrace = false, appendHexDumpToParseException = false)
val intCodec: JsonValueCodec[Int] = make[Int](CodecMakerConfig()) // don't define implicit for supported types
val stringCodec: JsonValueCodec[String] = make[String](CodecMakerConfig()) // don't define implicit for supported types
implicit val anyRefsCodec: JsonValueCodec[AnyRefs] = make[AnyRefs](CodecMakerConfig())
implicit val arraysCodec: JsonValueCodec[Arrays] = make[Arrays](CodecMakerConfig())
implicit val bigDecimalArrayCodec: JsonValueCodec[Array[BigDecimal]] = make[Array[BigDecimal]](CodecMakerConfig())
Expand Down Expand Up @@ -43,11 +45,9 @@ object JsoniterCodecs {
implicit val mutableIterablesCodec: JsonValueCodec[MutableIterables] = make[MutableIterables](CodecMakerConfig())
implicit val mutableMapsCodec: JsonValueCodec[MutableMaps] = make[MutableMaps](CodecMakerConfig())
implicit val intAndLongMapsCodec: JsonValueCodec[IntAndLongMaps] = make[IntAndLongMaps](CodecMakerConfig())
implicit val intCodec: JsonValueCodec[Int] = make[Int](CodecMakerConfig())
implicit val primitivesCodec: JsonValueCodec[Primitives] = make[Primitives](CodecMakerConfig())
implicit val extractFieldsCodec: JsonValueCodec[ExtractFields] = make[ExtractFields](CodecMakerConfig())
implicit val adtCodec: JsonValueCodec[AdtBase] = make[AdtBase](CodecMakerConfig())
implicit val stringCodec: JsonValueCodec[String] = make[String](CodecMakerConfig())
implicit val googleMapsAPICodec: JsonValueCodec[DistanceMatrix] = make[DistanceMatrix](CodecMakerConfig())
implicit val twitterAPICodec: JsonValueCodec[Seq[Tweet]] = make[Seq[Tweet]](CodecMakerConfig())
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class StringOfAsciiCharsBenchmark extends CommonParams {
def readJacksonScala(): String = jacksonMapper.readValue[String](jsonBytes)

@Benchmark
def readJsoniterScala(): String = readFromArray[String](jsonBytes)
def readJsoniterScala(): String = readFromArray[String](jsonBytes)(stringCodec)

@Benchmark
def readPlayJson(): String = Json.parse(jsonBytes).as[String]
Expand All @@ -38,10 +38,10 @@ class StringOfAsciiCharsBenchmark extends CommonParams {
def writeJacksonScala(): Array[Byte] = jacksonMapper.writeValueAsBytes(obj)

@Benchmark
def writeJsoniterScala(): Array[Byte] = writeToArray(obj)
def writeJsoniterScala(): Array[Byte] = writeToArray(obj)(stringCodec)

@Benchmark
def writeJsoniterScalaPrealloc(): Int = writeToPreallocatedArray(obj, preallocatedBuf, 0)
def writeJsoniterScalaPrealloc(): Int = writeToPreallocatedArray(obj, preallocatedBuf, 0)(stringCodec)

@Benchmark
def writePlayJson(): Array[Byte] = Json.toBytes(Json.toJson(obj))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class StringOfNonAsciiCharsBenchmark extends CommonParams {
def readJacksonScala(): String = jacksonMapper.readValue[String](jsonBytes)

@Benchmark
def readJsoniterScala(): String = readFromArray[String](jsonBytes)
def readJsoniterScala(): String = readFromArray[String](jsonBytes)(stringCodec)

@Benchmark
def readPlayJson(): String = Json.parse(jsonBytes).as[String]
Expand All @@ -38,10 +38,10 @@ class StringOfNonAsciiCharsBenchmark extends CommonParams {
def writeJacksonScala(): Array[Byte] = jacksonMapper.writeValueAsBytes(obj)

@Benchmark
def writeJsoniterScala(): Array[Byte] = writeToArray(obj)
def writeJsoniterScala(): Array[Byte] = writeToArray(obj)(stringCodec)

@Benchmark
def writeJsoniterScalaPrealloc(): Int = writeToPreallocatedArray(obj, preallocatedBuf, 0)
def writeJsoniterScalaPrealloc(): Int = writeToPreallocatedArray(obj, preallocatedBuf, 0)(stringCodec)

@Benchmark
def writePlayJson(): Array[Byte] = Json.toBytes(Json.toJson(obj))
Expand Down

0 comments on commit 741af95

Please sign in to comment.