From 2baa2df339ec79671456106c856043be512723ad Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 17 Mar 2023 22:49:12 +0800 Subject: [PATCH] update benchmarks --- bench/src-jvm/Main.scala | 59 ++++++++++++++++++++++++++++------------ bench/src/Common.scala | 43 +++++++---------------------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/bench/src-jvm/Main.scala b/bench/src-jvm/Main.scala index fa6f70cbb..2411e88e4 100644 --- a/bench/src-jvm/Main.scala +++ b/bench/src-jvm/Main.scala @@ -54,18 +54,18 @@ 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), @@ -73,20 +73,43 @@ object Main{ 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") diff --git a/bench/src/Common.scala b/bench/src/Common.scala index 888f67c8b..97ca82aa0 100644 --- a/bench/src/Common.scala +++ b/bench/src/Common.scala @@ -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 { @@ -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") + } }