aboutsummaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorKevin Laeufer2020-07-08 11:46:51 -0700
committerGitHub2020-07-08 18:46:51 +0000
commit05ba1c9d52c056e33b4121ea55812ae596016ea3 (patch)
tree14e4df6e6d7435109c9f4956667c27c9dec45aa0 /benchmark
parent26564304e028a015bdcb9f1a6889f7847a3a5140 (diff)
ir: add faster serializer (#1694)
This Serializer which is implemented external to the IR node definition uses a StringBuilder to achieve about a 1.7x performance improvement when serializing. Eventually, all implementations of the `serialize` methd should be replaced with a call to `Serializer.serialize`. However, for this PR we keep the old code in place in order to allow for easy regression testing with the benchmark JAR like this: > java -cp utils/bin/firrtl-benchmark.jar \ firrtl.benchmark.hot.SerializationBenchmark \ ~/benchmarks/medium.pb 2 5 test Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/src/main/scala/firrtl/benchmark/hot/SerializationBenchmark.scala40
1 files changed, 40 insertions, 0 deletions
diff --git a/benchmark/src/main/scala/firrtl/benchmark/hot/SerializationBenchmark.scala b/benchmark/src/main/scala/firrtl/benchmark/hot/SerializationBenchmark.scala
new file mode 100644
index 00000000..e6ef04ec
--- /dev/null
+++ b/benchmark/src/main/scala/firrtl/benchmark/hot/SerializationBenchmark.scala
@@ -0,0 +1,40 @@
+// See LICENSE for license details.
+package firrtl.benchmark.hot
+
+import firrtl.benchmark.util._
+import firrtl.ir.Serializer
+
+object SerializationBenchmark extends App {
+ val inputFile = args(0)
+ val warmup = args(1).toInt
+ val runs = args(2).toInt
+ val select = if(args.length > 3) args(3) else "o"
+
+ val input = filenameToCircuit(inputFile)
+
+ if(select == "n") {
+ println("Benchmarking new Serializer.serialize")
+ firrtl.benchmark.hot.util.benchmark(warmup, runs)(Serializer.serialize(input))
+ } else if(select == "o") {
+ println("Benchmarking legacy serialization")
+ firrtl.benchmark.hot.util.benchmark(warmup, runs)(input.serialize)
+ } else if(select.startsWith("test")) {
+ println("Testing the new serialization against the old one")
+ val o = input.serialize.split('\n').filterNot(_.trim.isEmpty)
+ val n = Serializer.serialize(input).split('\n').filterNot(_.trim.isEmpty)
+ val silent = select.endsWith("silent")
+
+ println(s"Old lines: ${o.length}")
+ println(s"New lines: ${n.length}")
+ o.zip(n).zipWithIndex.foreach { case ((ol, nl), ii) =>
+ if(ol != nl) {
+ println(s"❌@$ii OLD: |$ol|")
+ println(s"❌@$ii NEW: |$nl|")
+ throw new RuntimeException()
+ } else if(!silent) {
+ println(s"✅ |$ol")
+ }
+ }
+
+ }
+}