Skip to content

Commit

Permalink
Reformat with scalafmt 3.7.11
Browse files Browse the repository at this point in the history
Executed command: scalafmt --non-interactive
  • Loading branch information
scala-steward committed Jul 28, 2023
1 parent f3f936c commit ce4a4d9
Show file tree
Hide file tree
Showing 136 changed files with 38,133 additions and 4,553 deletions.
68 changes: 49 additions & 19 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ ThisBuild / scalaVersion := scala3
lazy val commonSettings = Seq(
version := "0.28.0",
organization := "com.tethys-json",
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
licenses := Seq(
"Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")
),
homepage := Some(url("https://github.com/tethys-json/tethys")),
scmInfo := Some(
ScmInfo(
Expand Down Expand Up @@ -38,7 +40,9 @@ lazy val commonSettings = Seq(
url = url("https://github.com/MrIrre")
)
),
credentials ++= Option(Path.userHome / ".config" / "sbt" / ".tethys-credentials")
credentials ++= Option(
Path.userHome / ".config" / "sbt" / ".tethys-credentials"
)
.filter(_.exists())
.map(Credentials(_)),
publishMavenStyle := true,
Expand All @@ -54,7 +58,8 @@ lazy val commonSettings = Seq(
def crossScalaSettings = {
def addDirsByScalaVersion(path: String): Def.Initialize[Seq[sbt.File]] =
scalaVersion.zip(baseDirectory) { case (v, base) =>
def extraDirs(versionSpecificFolder: String): Seq[sbt.File] = Seq(base / path / versionSpecificFolder)
def extraDirs(versionSpecificFolder: String): Seq[sbt.File] =
Seq(base / path / versionSpecificFolder)

CrossVersion.partialVersion(v) match {
case Some((2, y)) if y >= 13 =>
Expand All @@ -67,8 +72,12 @@ def crossScalaSettings = {

Seq(
crossScalaVersions := Seq(scala213, scala3),
Compile / unmanagedSourceDirectories ++= addDirsByScalaVersion("src/main").value,
Test / unmanagedSourceDirectories ++= addDirsByScalaVersion("src/test").value
Compile / unmanagedSourceDirectories ++= addDirsByScalaVersion(
"src/main"
).value,
Test / unmanagedSourceDirectories ++= addDirsByScalaVersion(
"src/test"
).value
)
}

Expand All @@ -79,13 +88,24 @@ lazy val testSettings = Seq(
)
)

lazy val tethys = project.in(file("."))
lazy val tethys = project
.in(file("."))
.settings(
publishTo := None,
crossScalaVersions := Seq.empty,
commonSettings
)
.aggregate(core, `macro-derivation`, `jackson-211`, `jackson-212`, `jackson-213`, json4s, circe, refined, enumeratum)
.aggregate(
core,
`macro-derivation`,
`jackson-211`,
`jackson-212`,
`jackson-213`,
json4s,
circe,
refined,
enumeratum
)

lazy val modules = file("modules")

Expand All @@ -98,7 +118,8 @@ def addScalaCompiler(scalaVersion: String): Seq[ModuleID] =
case _ => Seq.empty
}

lazy val core = project.in(modules / "core")
lazy val core = project
.in(modules / "core")
.settings(crossScalaSettings)
.settings(commonSettings)
.settings(testSettings)
Expand All @@ -107,7 +128,8 @@ lazy val core = project.in(modules / "core")
libraryDependencies ++= addScalaCompiler(scalaVersion.value)
)

lazy val `macro-derivation` = project.in(modules / "macro-derivation")
lazy val `macro-derivation` = project
.in(modules / "macro-derivation")
.settings(crossScalaSettings)
.settings(commonSettings)
.settings(testSettings)
Expand All @@ -123,7 +145,8 @@ lazy val jacksonSettings = Seq(
Test / unmanagedResourceDirectories += modules / "jackson-backend" / "src" / "test" / "resources"
)

lazy val `jackson-211` = project.in(modules / "jackson-211")
lazy val `jackson-211` = project
.in(modules / "jackson-211")
.settings(crossScalaSettings)
.settings(commonSettings)
.settings(jacksonSettings)
Expand All @@ -136,7 +159,8 @@ lazy val `jackson-211` = project.in(modules / "jackson-211")
)
.dependsOn(core)

lazy val `jackson-212` = project.in(modules / "jackson-212")
lazy val `jackson-212` = project
.in(modules / "jackson-212")
.settings(crossScalaSettings)
.settings(commonSettings)
.settings(jacksonSettings)
Expand All @@ -149,7 +173,8 @@ lazy val `jackson-212` = project.in(modules / "jackson-212")
)
.dependsOn(core)

lazy val `jackson-213` = project.in(modules / "jackson-213")
lazy val `jackson-213` = project
.in(modules / "jackson-213")
.settings(crossScalaSettings)
.settings(commonSettings)
.settings(jacksonSettings)
Expand All @@ -162,7 +187,8 @@ lazy val `jackson-213` = project.in(modules / "jackson-213")
)
.dependsOn(core)

lazy val circe = project.in(modules / "circe")
lazy val circe = project
.in(modules / "circe")
.settings(crossScalaSettings)
.settings(commonSettings)
.settings(testSettings)
Expand All @@ -174,7 +200,8 @@ lazy val circe = project.in(modules / "circe")
)
.dependsOn(core, `jackson-212` % Test)

lazy val json4s = project.in(modules / "json4s")
lazy val json4s = project
.in(modules / "json4s")
.settings(crossScalaSettings)
.settings(commonSettings)
.settings(testSettings)
Expand All @@ -186,7 +213,8 @@ lazy val json4s = project.in(modules / "json4s")
)
.dependsOn(core)

lazy val enumeratum = project.in(modules / "enumeratum")
lazy val enumeratum = project
.in(modules / "enumeratum")
.settings(crossScalaSettings)
.settings(commonSettings)
.settings(testSettings)
Expand All @@ -203,7 +231,8 @@ lazy val enumeratum = project.in(modules / "enumeratum")
)
.dependsOn(core)

lazy val refined = project.in(modules / "refined")
lazy val refined = project
.in(modules / "refined")
.settings(crossScalaSettings)
.settings(commonSettings)
.settings(testSettings)
Expand All @@ -215,7 +244,8 @@ lazy val refined = project.in(modules / "refined")
)
.dependsOn(core)

lazy val benchmarks = project.in(modules / "benchmarks")
lazy val benchmarks = project
.in(modules / "benchmarks")
.settings(crossScalaSettings)
.settings(commonSettings)
.settings(
Expand All @@ -229,12 +259,12 @@ lazy val benchmarks = project.in(modules / "benchmarks")
"io.circe" %% "circe-jawn" % "0.14.3",
"io.circe" %% "circe-jackson210" % "0.14.0",
"com.typesafe.play" %% "play-json" % "2.10.0-RC7",
"org.knowm.xchart" % "xchart" % "3.8.2" exclude("de.erichseifert.vectorgraphics2d", "VectorGraphics2D") withSources()
"org.knowm.xchart" % "xchart" % "3.8.2" exclude ("de.erichseifert.vectorgraphics2d", "VectorGraphics2D") withSources ()
),
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("-Ymacro-annotations")
case _ => Seq.empty
case _ => Seq.empty
}
}
)
Expand Down
98 changes: 65 additions & 33 deletions modules/benchmarks/src/main/scala/json/bench/BenchMarkdown.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,55 @@ 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 "tethys-jackson" => 1
case "pure-jackson" => 2
case "circe" => 3
case "circe-jawn" => 4
case "circe-jackson" => 5
case "java.lang.StringBuilder" => 6
case "scala.StringBuilder" => 7
case "json4s-jackson" => 8
case "json4s-native" => 9
case "play-json" => 10
case "spray-json" => 11
case "pushka" => 12
case _ => 13
case "scala.StringBuilder" => 7
case "json4s-jackson" => 8
case "json4s-native" => 9
case "play-json" => 10
case "spray-json" => 11
case "pushka" => 12
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 @@ -64,14 +77,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 @@ -89,7 +109,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 @@ -100,16 +120,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 @@ -118,12 +147,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 @@ -133,7 +165,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
Loading

0 comments on commit ce4a4d9

Please sign in to comment.