Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scalafmt-core to 3.7.17 #262

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.7.17
0a87fd464d9a29429865dbdab50ebb982419a9d4
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=3.7.1
version=3.7.17
runner.dialect=scala3
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import tethys.jackson._

object TethysBench {

implicit val dataWriter: JsonWriter[Data] = tethys.derivation.semiauto.jsonWriter[Data]
implicit val dataReader: JsonReader[Data] = tethys.derivation.semiauto.jsonReader[Data]
implicit val dataWriter: JsonWriter[Data] =
tethys.derivation.semiauto.jsonWriter[Data]
implicit val dataReader: JsonReader[Data] =
tethys.derivation.semiauto.jsonReader[Data]

object TethysJacksonDataProcessor extends DataWriter with DataReader {

override def write(seq: Seq[Data]): String = seq.asJson

override def read(json: String): Seq[Data] = json.jsonAs[Seq[Data]].toOption.get
override def read(json: String): Seq[Data] =
json.jsonAs[Seq[Data]].toOption.get
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import json.bench.{DataReader, DataWriter}
import tethys.*
import tethys.jackson.*

/**
* Created by eld0727 on 21.04.17.
/** Created by eld0727 on 21.04.17.
*/
object TethysBench {

Expand All @@ -17,6 +16,7 @@ object TethysBench {

override def write(seq: Seq[Data]): String = seq.asJson

override def read(json: String): Seq[Data] = json.jsonAs[Seq[Data]].toOption.get
override def read(json: String): Seq[Data] =
json.jsonAs[Seq[Data]].toOption.get
}
}
94 changes: 63 additions & 31 deletions modules/benchmarks/src/main/scala/json/bench/BenchMarkdown.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,53 @@ object BenchMarkdown {
val benchmarksOrdering: Ordering[String] = Ordering.by[String, Int] {
case "Parsing" | "json.bench.JmhReaderBench.bench" => 1
case "Writing" | "json.bench.JmhWriterBench.bench" => 2
case _ => 3
case _ => 3
}

val processorsOrdering: Ordering[String] = Ordering.by[String, Int] {
case "tethys-jackson" => 1
case "pure-jackson" => 2
case "circe" => 3
case "circe-jawn" => 4
case "circe-jackson" => 5
case "pure-jackson" => 2
case "circe" => 3
case "circe-jawn" => 4
case "circe-jackson" => 5
case "json4s-jackson" => 8
case "json4s-native" => 9
case "play-json" => 10
case "spray-json" => 11
case "pushka" => 12
case "zio-json" => 13
case _ => 13
case "json4s-native" => 9
case "play-json" => 10
case "spray-json" => 11
case "pushka" => 12
case "zio-json" => 13
case _ => 13
}

val namesMapping = Map(
"json.bench.JmhReaderBench.bench" -> "Parsing",
"json.bench.JmhWriterBench.bench" -> "Writing"
)

implicit val mbScore: JsonReader[Either[String, Double]] = new JsonReader[Either[String, Double]] {
override def read(it: TokenIterator)(implicit fieldName: FieldName): Either[String, Double] = {
if(it.currentToken().isNumberValue) Right(Math.round(JsonReader.doubleReader.read(it) * 1000) / 1000.0)
else Left(JsonReader.stringReader.read(it))
implicit val mbScore: JsonReader[Either[String, Double]] =
new JsonReader[Either[String, Double]] {
override def read(
it: TokenIterator
)(implicit fieldName: FieldName): Either[String, Double] = {
if (it.currentToken().isNumberValue)
Right(Math.round(JsonReader.doubleReader.read(it) * 1000) / 1000.0)
else Left(JsonReader.stringReader.read(it))
}
}
}
implicit val primaryMetricsReader: JsonReader[PrimaryMetrics] = jsonReader[PrimaryMetrics]
implicit val primaryMetricsReader: JsonReader[PrimaryMetrics] =
jsonReader[PrimaryMetrics]
implicit val benchmarkReader: JsonReader[Benchmark] = jsonReader[Benchmark]

case class Benchmark(benchmark: String, mode: String, params: mutable.LinkedHashMap[String, String], primaryMetric: PrimaryMetrics)
case class PrimaryMetrics(score: Either[String, Double], scoreError: Either[String, Double])
case class Benchmark(
benchmark: String,
mode: String,
params: mutable.LinkedHashMap[String, String],
primaryMetric: PrimaryMetrics
)
case class PrimaryMetrics(
score: Either[String, Double],
scoreError: Either[String, Double]
)

def readBenchmarks(dir: String, file: String): Seq[Benchmark] = {
val jhmResultsPath = Paths.get(dir, file)
Expand All @@ -62,14 +75,21 @@ object BenchMarkdown {

def main(args: Array[String]): Unit = {
val List(dir) = args.toList
val benchs = readBenchmarks(dir, "jmh-reader.json") ++ readBenchmarks(dir, "jmh-writer.json")
val benchs = readBenchmarks(dir, "jmh-reader.json") ++ readBenchmarks(
dir,
"jmh-writer.json"
)
val grouped = benchs.groupBy(_.benchmark)
val mainTables = grouped.toList.sortBy(_._1)(benchmarksOrdering).map {
case (name, benchmarks) =>
val rows = benchmarks.map(_.params(nameColumn)).distinct.sorted(processorsOrdering)
val rows = benchmarks
.map(_.params(nameColumn))
.distinct
.sorted(processorsOrdering)
val colls = benchmarks.map(_.params(sizeColumn)).distinct
val data = benchmarks.map { b =>
(b.params(nameColumn), b.params(sizeColumn)) -> b.primaryMetric.score.fold(identity, _.toString)
(b.params(nameColumn), b.params(sizeColumn)) -> b.primaryMetric.score
.fold(identity, _.toString)
}.toMap

s"""
Expand All @@ -87,7 +107,7 @@ object BenchMarkdown {
private def chart(name: String, bs: Seq[Benchmark], dir: String): String = {
val title = namesMapping.getOrElse(name, name)
val images = Paths.get(dir, "images")
if(Files.notExists(images)) {
if (Files.notExists(images)) {
Files.createDirectory(images)
}
val imgPath = dir + "/images/" + title + "Performance"
Expand All @@ -98,16 +118,25 @@ object BenchMarkdown {
""".stripMargin
}

private def table(rows: Seq[String], columns: Seq[String], data: Map[(String, String), String]): String = {
private def table(
rows: Seq[String],
columns: Seq[String],
data: Map[(String, String), String]
): String = {
val header = columns.foldLeft("name \\ size")(_ + "|" + _)
val line = columns.map(_ => "---").foldLeft("---")(_ + "|" + _)
val dataLines = rows.map { row =>
columns.map(col => data.getOrElse((row, col), " ")).foldLeft(row)(_ + "|" + _)
columns
.map(col => data.getOrElse((row, col), " "))
.foldLeft(row)(_ + "|" + _)
}
dataLines.foldLeft(header + "\n" + line)(_ + "\n" + _)
}

private def buildPerformanceChart(title: String, benchmarks: Seq[Benchmark]): CategoryChart = {
private def buildPerformanceChart(
title: String,
benchmarks: Seq[Benchmark]
): CategoryChart = {
val chart: CategoryChart = new CategoryChartBuilder()
.width(940)
.height(400)
Expand All @@ -116,12 +145,15 @@ object BenchMarkdown {
.xAxisTitle("size")
.build()

val maxs = benchmarks.groupBy(_.params(sizeColumn)).map {
case (size, bs) => size -> bs.map(_.primaryMetric.score.fold(_ => 0.0, identity)).max
val maxs = benchmarks.groupBy(_.params(sizeColumn)).map { case (size, bs) =>
size -> bs.map(_.primaryMetric.score.fold(_ => 0.0, identity)).max
}

benchmarks.groupBy(_.params(nameColumn)).toList.sortBy(_._1)(processorsOrdering).foreach {
case (name, bs) =>
benchmarks
.groupBy(_.params(nameColumn))
.toList
.sortBy(_._1)(processorsOrdering)
.foreach { case (name, bs) =>
import scala.collection.JavaConverters._

val data = bs.map { b =>
Expand All @@ -131,7 +163,7 @@ object BenchMarkdown {
val xData = data.map(_._1).asJava
val yData = data.map(t => Double.box(t._2)).asJava
chart.addSeries(name, xData, yData)
}
}

chart
}
Expand Down
46 changes: 25 additions & 21 deletions modules/benchmarks/src/main/scala/json/bench/JmhReaderBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,44 @@ import org.openjdk.jmh.annotations.{State, _}
@Fork(value = 1, jvmArgsAppend = Array("-Xms1G", "-Xmx1G"))
@State(Scope.Benchmark)
class JmhReaderBench {
@Param(Array(
"128b",
"1kb",
"128kb",
"1mb",
"32mb"
))
@Param(
Array(
"128b",
"1kb",
"128kb",
"1mb",
"32mb"
)
)
var jsonSize: String = _

val seed = 10000

var data: String =_
var data: String = _

@Setup(Level.Trial)
def setup(): Unit = {
val entities = jsonSize match {
case "128b" => Data.dataSamples(1, seed)
case "1kb" => Data.dataSamples(8, seed)
case "128b" => Data.dataSamples(1, seed)
case "1kb" => Data.dataSamples(8, seed)
case "128kb" => Data.dataSamples(128 * 8, seed)
case "1mb" => Data.dataSamples(8 * 128 * 8, seed)
case "32mb" => Data.dataSamples(32 * 8 * 128 * 8, seed)
case "1mb" => Data.dataSamples(8 * 128 * 8, seed)
case "32mb" => Data.dataSamples(32 * 8 * 128 * 8, seed)
}
data = TethysJacksonDataProcessor.write(entities)
}

@Param(Array(
"tethys-jackson",
"pure-jackson",
"circe-jawn",
"circe-jackson",
"play-json",
"spray-json",
"zio-json"
))
@Param(
Array(
"tethys-jackson",
"pure-jackson",
"circe-jawn",
"circe-jackson",
"play-json",
"spray-json",
"zio-json"
)
)
var processorName: String = _

@Benchmark
Expand Down
42 changes: 23 additions & 19 deletions modules/benchmarks/src/main/scala/json/bench/JmhWriterBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import org.openjdk.jmh.annotations._
@Fork(value = 1, jvmArgsAppend = Array("-Xms1G", "-Xmx1G"))
@State(Scope.Benchmark)
class JmhWriterBench {
@Param(Array(
"128b",
"1kb",
"128kb",
"1mb",
"32mb"
))
@Param(
Array(
"128b",
"1kb",
"128kb",
"1mb",
"32mb"
)
)
var jsonSize: String = _

val seed = 10000
Expand All @@ -27,22 +29,24 @@ class JmhWriterBench {
@Setup(Level.Trial)
def setup(): Unit = {
data = jsonSize match {
case "128b" => Data.dataSamples(1, seed)
case "1kb" => Data.dataSamples(8, seed)
case "128b" => Data.dataSamples(1, seed)
case "1kb" => Data.dataSamples(8, seed)
case "128kb" => Data.dataSamples(128 * 8, seed)
case "1mb" => Data.dataSamples(8 * 128 * 8, seed)
case "32mb" => Data.dataSamples(32 * 8 * 128 * 8, seed)
case "1mb" => Data.dataSamples(8 * 128 * 8, seed)
case "32mb" => Data.dataSamples(32 * 8 * 128 * 8, seed)
}
}

@Param(Array(
"tethys-jackson",
"pure-jackson",
"circe",
"play-json",
"spray-json",
"zio-json"
))
@Param(
Array(
"tethys-jackson",
"pure-jackson",
"circe",
"play-json",
"spray-json",
"zio-json"
)
)
var processorName: String = _

@Benchmark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ object CirceBench {
}

object CirceJawnDataReader extends DataReader {
override def read(json: String): Seq[Data] = jawn.decode[Seq[Data]](json).toOption.get
override def read(json: String): Seq[Data] =
jawn.decode[Seq[Data]](json).toOption.get
}

object CirceJacksonDataReader extends DataReader {
override def read(json: String): Seq[Data] = jackson.decode[Seq[Data]](json).toOption.get
override def read(json: String): Seq[Data] =
jackson.decode[Seq[Data]](json).toOption.get
}
}
Loading
Loading