Skip to content

Commit 8958d26

Browse files
committed
Show error bars
1 parent bbcb391 commit 8958d26

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ val timeBenchmark =
3030
// runs the benchmarks and produce charts
3131
InputKey[Unit]("charts") := {
3232
val benchmarks = Def.spaceDelimited().parsed
33-
val targetDir = crossTarget.value / "bencharts"
33+
val targetDir = crossTarget.value
3434
val jmhReport = targetDir / "jmh-result.json"
3535
val jmhArgs = s" -rf json -rff ${jmhReport.absolutePath} $benchmarks"
3636
// HACK We should use `jmhArgs` here
37-
val _ = (run in Jmh).partialInput(" -rf json -rff target/scala-2.12/bencharts/jmh-result.json").evaluated
37+
val _ = (run in Jmh).partialInput(" -rf json -rff target/scala-2.12/jmh-result.json").evaluated
3838
strawman.collection.Bencharts(jmhReport, targetDir)
3939
}
4040
)

project/Bencharts.scala

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import javax.imageio.ImageIO
55
import org.jfree.chart.JFreeChart
66
import org.jfree.chart.axis.{LogAxis, NumberAxis}
77
import org.jfree.chart.plot.XYPlot
8-
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer
9-
import org.jfree.data.xy.{XYSeries, XYSeriesCollection}
8+
import org.jfree.chart.renderer.xy.XYErrorRenderer
9+
import org.jfree.data.xy.{YIntervalSeries, YIntervalSeriesCollection}
1010
import play.api.libs.json.{JsObject, Json}
1111
import sbt._
1212

@@ -36,32 +36,36 @@ object Bencharts {
3636
// group by concrete collection type
3737
.groupBy(result => (result \ "benchmark").as[String].stripSuffix(benchmark))
3838
.map { case (collectionType, iterations) =>
39-
val xySeries = new XYSeries(collectionType)
39+
val ySeries = new YIntervalSeries(collectionType)
4040
// each benchmark has been run with several collection sizes (8, 64, 512, etc.)
4141
// we add a point for each of these iterations
4242
for (iteration <- iterations) {
43-
xySeries.add(
43+
ySeries.add(
4444
(iteration \ "params" \ "size").as[String].toDouble,
45-
(iteration \ "primaryMetric" \ "score").as[Double]
45+
(iteration \ "primaryMetric" \ "score").as[Double],
46+
(iteration \ "primaryMetric" \ "scoreConfidence").apply(0).as[Double],
47+
(iteration \ "primaryMetric" \ "scoreConfidence").apply(1).as[Double]
4648
)
4749
}
48-
xySeries
50+
ySeries
4951
}
5052

5153
val xAxis = new LogAxis("Size")
5254
xAxis.setBase(2)
5355
xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits())
5456
val yAxis = new LogAxis("Execution time (lower is better)")
5557

56-
val col = new XYSeriesCollection()
57-
for (series <- seriess) {
58+
val col = new YIntervalSeriesCollection()
59+
val renderer = new XYErrorRenderer
60+
for ((series, i) <- seriess.zipWithIndex) {
5861
col.addSeries(series)
62+
renderer.setSeriesLinesVisible(i, true)
5963
}
6064

6165
val plot = new XYPlot(
6266
col,
6367
xAxis, yAxis,
64-
new XYLineAndShapeRenderer(true, true)
68+
renderer
6569
)
6670

6771
val chart = new JFreeChart(
@@ -72,7 +76,7 @@ object Bencharts {
7276
)
7377

7478
ImageIO.write(
75-
chart.createBufferedImage(640, 480),
79+
chart.createBufferedImage(800, 600),
7680
"png",
7781
targetDir / s"$benchmark.png"
7882
)

0 commit comments

Comments
 (0)