summaryrefslogtreecommitdiff
path: root/test/benchmarks/src/main/scala/scala/collection/mutable/OpenHashMapRunner.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/benchmarks/src/main/scala/scala/collection/mutable/OpenHashMapRunner.scala')
-rw-r--r--test/benchmarks/src/main/scala/scala/collection/mutable/OpenHashMapRunner.scala60
1 files changed, 34 insertions, 26 deletions
diff --git a/test/benchmarks/src/main/scala/scala/collection/mutable/OpenHashMapRunner.scala b/test/benchmarks/src/main/scala/scala/collection/mutable/OpenHashMapRunner.scala
index 1a58b18ee9..b14b733a81 100644
--- a/test/benchmarks/src/main/scala/scala/collection/mutable/OpenHashMapRunner.scala
+++ b/test/benchmarks/src/main/scala/scala/collection/mutable/OpenHashMapRunner.scala
@@ -1,20 +1,18 @@
package scala.collection.mutable
-import java.io.BufferedWriter
import java.io.File
-import java.io.FileOutputStream
-import java.io.OutputStreamWriter
import java.io.PrintWriter
-import scala.collection.JavaConversions
+
import scala.language.existentials
+
+import org.openjdk.jmh.results.Result
import org.openjdk.jmh.results.RunResult
import org.openjdk.jmh.runner.Runner
import org.openjdk.jmh.runner.options.CommandLineOptions
-import org.openjdk.jmh.runner.options.Options
-import benchmark.JmhRunner
import org.openjdk.jmh.runner.options.OptionsBuilder
import org.openjdk.jmh.runner.options.VerboseMode
-import org.openjdk.jmh.results.Result
+
+import benchmark.JmhRunner
/** Replacement JMH application that runs the [[OpenHashMap]] benchmark.
*
@@ -27,6 +25,7 @@ object OpenHashMapRunner extends JmhRunner {
/** Qualifier to add to the name of a memory usage data set. */
private[this] val memoryDatasetQualifier = "-memory"
+ /** Adapter to the JMH result class that simplifies our method calls. */
private[this] implicit class MyRunResult(r: RunResult) {
/** Return the dataset label. */
def label = r.getPrimaryResult.getLabel
@@ -34,13 +33,13 @@ object OpenHashMapRunner extends JmhRunner {
/** Return the value of the JMH parameter for the number of map entries per invocation. */
def size: String = r.getParams.getParam("size")
- /** Return the operation counts. */
+ /** Return the operation counts. Not every test tracks this. */
def operations = Option(r.getSecondaryResults.get("operations"))
/** Return the number of map entries. */
def entries = r.getSecondaryResults.get("mapEntries")
- /** Return the memory usage. */
+ /** Return the memory usage. Only defined if memory usage was measured. */
def memory = Option(r.getSecondaryResults.get("memory"))
}
@@ -50,7 +49,6 @@ object OpenHashMapRunner extends JmhRunner {
def main(args: Array[String]) {
import scala.collection.JavaConversions._
- import scala.language.existentials
val opts = new CommandLineOptions(args: _*)
var builder = new OptionsBuilder().parent(opts).jvmArgsPrepend("-Xmx6000m")
@@ -58,7 +56,12 @@ object OpenHashMapRunner extends JmhRunner {
val results = new Runner(builder.build).run()
- // Sort the results
+ /* Sort the JMH results into "data sets", each representing a complete test of one feature.
+ * Some results only measure CPU performance; while others also measure memory usage, and
+ * thus are split into two data sets. A data set is distinguished by its label, which is
+ * the label of the JMH result, for CPU performance, or that with an added suffix, for memory
+ * usage.
+ */
/** Map from data set name to data set. */
val datasetByName = Map.empty[String, Set[RunResult]]
@@ -83,23 +86,28 @@ object OpenHashMapRunner extends JmhRunner {
val f = new PrintWriter(outputFile, "UTF-8")
try {
- datasetByName.foreach(_ match { case (label: String, dataset: Iterable[RunResult]) => {
- f.println(s"# [$label]")
-
- val isMemoryUsageDataset = label.endsWith(memoryDatasetQualifier)
- dataset.foreach { r =>
- f.println(r.size + " " + (
- if (isMemoryUsageDataset)
- stats(r.entries) + " " + stats(r.memory.get)
- else
- stats(r.operations getOrElse r.getPrimaryResult)
- ))
- }
-
- f.println(); f.println() // data set separator
- }})
+ datasetByName.foreach(_ match {
+ case (label: String, dataset: Iterable[RunResult]) =>
+ outputDataset(f, label, dataset)
+ })
} finally {
f.close()
}
}
+
+ private[this] def outputDataset(f: PrintWriter, label: String, dataset: Iterable[RunResult]) {
+ f.println(s"# [$label]")
+
+ val isMemoryUsageDataset = label.endsWith(memoryDatasetQualifier)
+ dataset.foreach { r =>
+ f.println(r.size + " " + (
+ if (isMemoryUsageDataset && !r.memory.get.getScore.isInfinite)
+ stats(r.entries) + " " + stats(r.memory.get)
+ else
+ stats(r.operations getOrElse r.getPrimaryResult)
+ ))
+ }
+
+ f.println(); f.println() // data set separator
+ }
}