Skip to content

Commit

Permalink
update benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Mar 17, 2023
1 parent 8d8fea9 commit 2baa2df
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
59 changes: 41 additions & 18 deletions bench/src-jvm/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,62 @@ object Main{
// benchParsingRendering(duration, bytes = false, strings = true, streams = false, msgpack = false)
// benchParsingRendering(duration, bytes = false, strings = false, streams = true, msgpack = false)
// benchParsingRendering(duration, bytes = false, strings = false, streams = false, msgpack = true)
// Common.integers(duration),
// Common.integersByteArray(duration),
// Common.integersBinary(duration),
//
// Common.doubles(duration),
// Common.doublesByteArray(duration),
// Common.doublesBinary(duration),
//
// Common.sequences(duration),
// Common.sequencesByteArray(duration),
// Common.sequencesBinary(duration),
//
Common.integers(duration),
Common.integersByteArray(duration),
Common.integersBinary(duration),

Common.doubles(duration),
Common.doublesByteArray(duration),
Common.doublesBinary(duration),

Common.sequences(duration),
Common.sequencesByteArray(duration),
Common.sequencesBinary(duration),

Common.shortStrings(duration),
Common.shortStringsByteArray(duration),
Common.shortStringsBinary(duration),

Common.longStrings(duration),
Common.longStringsByteArray(duration),
Common.longStringsBinary(duration),
//

Common.unicodeStrings(duration),
Common.unicodeStringsByteArray(duration),
Common.unicodeStringsBinary(duration),
//
// Common.caseClasses(duration),
// Common.caseClassesByteArray(duration),
// Common.caseClassesBinary(duration)

Common.caseClasses(duration),
Common.caseClassesByteArray(duration),
Common.caseClassesBinary(duration)
)

if (save) allResults.appendAll(results.flatten)
println()
}
Common.prettyPrintResults(allResults)
val prettyResults = Common.prettyPrintResults(allResults)
println(prettyResults)
for(savePath <- args.headOption){
val p = java.nio.file.Paths.get(savePath)
if (!java.nio.file.Files.exists(p)) java.nio.file.Files.write(p, prettyResults.getBytes)
else {
val before = new String(java.nio.file.Files.readAllBytes(p))
def split(s: String) = s.linesIterator.map(_.drop(2).dropRight(2).split(" *\\| *")).toList
println(
split(prettyResults).zip(split(before)).map {
case (afterLine, beforeLine) =>
afterLine.zip(beforeLine) match {
case Array(head, tail@_*) =>
Array(head._1) ++ tail.map { case (a, b) =>
val percentChange = ((a.toDouble / b.toDouble - 1) * 100).toInt
val sign =
if (percentChange == 0) "" else if (percentChange < 0) "-" else if (percentChange > 0) "+"
s"$b -> $a (${sign}${math.abs(percentChange)}%)"
}
}
}.map(_.mkString("| ", " | ", " |")).mkString("\n")
)
}
}
}

@nowarn("cat=deprecation")
Expand Down
43 changes: 10 additions & 33 deletions bench/src/Common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ object Common{
Seq(readResult, writeResult)
}

def prettyPrintResults(allResults: collection.Seq[(String, Int)]) = {
def prettyPrintResults(allResults: collection.Seq[(String, Int)]): String = {
@nowarn("cat=deprecation")
val groupedResults = allResults
.map {
Expand All @@ -439,37 +439,14 @@ object Common{
.groupMap { case ((name, tag), v) => name } { case ((name, tag), v) => (tag, v) }.mapValues(_.toMap)

val tags = Seq("JsonString", "JsonByteArray", "MsgPack")
println("| Name | " + tags.mkString(" | ") + " |")
println("|---:| " + tags.map(_ => "---:").mkString(" | ") + " |")
for ((name, taggedValues) <- groupedResults.toList.sortBy(t => allResults.map(_._1).indexOf(t._1))) {
println(s"| $name | " + tags.map(taggedValues.getOrElse(_, " ")).mkString(" | ") + " |")
}
}
val lines = Seq(
"| Name | " + tags.mkString(" | ") + " |",
"|---:| " + tags.map(_ => "---:").mkString(" | ") + " |"
) ++ (
for ((name, taggedValues) <- groupedResults.toList.sortBy(t => allResults.map(_._1).indexOf(t._1)))
yield s"| $name | " + tags.map(taggedValues.getOrElse(_, " ")).mkString(" | ") + " |"
)

// REPL snippet to combine multiple table bodies into
// one, with % improvement or regression

// {
// def split(s: String) = s.linesIterator.map(_.drop(2).dropRight(2).split(" *\\| *")).toList
// split(after).zip(split(before)).map{
// case (afterLine, beforeLine) =>
// afterLine.zip(beforeLine)match{
// case Array(head, tail@_*) =>
// Array(head._1) ++ tail.map{case (a, b) =>
// val percentChange = ((a.toDouble / b.toDouble - 1) * 100).toInt
// val sign =
// if (percentChange == 0) "" else
// if (percentChange < 0) "-" else
// if (percentChange > 0) "+"
// s"$b -> $a (${sign}${percentChange}%)"
// }
// }
// }.map(_.mkString("| "," | "," |")).mkString("\n")
// }

// Can be run with
//
// git checkout optimize && ./mill bench.jvm.run && git checkout main && git checkout optimize bench && ./mill bench.jvm.run &&
// git checkout optimize && ./mill bench.js.run && git checkout main && git checkout optimize bench && ./mill bench.js.run &&
// git checkout optimize && ./mill bench.native.run && git checkout main && git checkout optimize bench && ./mill bench.native.run
lines.mkString("\n")
}
}

0 comments on commit 2baa2df

Please sign in to comment.