I'm trying to microbenchmark two different implementations of calculating a running median using Scalameter. I've some test files, small and large, from where the numbers are going to come from. Problem is, the following code completes instantly without generating any sort of benchmark at all.
object MedianMaintenanceBenchmark extends Bench[Double] {
/* configuration */
lazy val executor = LocalExecutor(
new Warmer.Default,
Aggregator.median[Double],
measurer
)
lazy val measurer = new Measurer.Default
lazy val reporter = new LoggingReporter[Double]
lazy val persistor: Persistor.None.type = Persistor.None
/* inputs */
private val files: Gen[String] = Gen.enumeration("files")("median-test")
private val num: Gen[Seq[Int]] = (for (f <- files) yield numbers(f)).cached
/* tests */
performance of "MedianMaintenance" config (
exec.benchRuns -> 10
) in {
measure method "using heap" in {
using(num) in {
xs => MedianMaintenanceUsingHeaps(xs).medians
}
}
}
private def numbers(filename: String): Seq[Int] = // elided
}
Output:
::Benchmark MedianMaintenance.using heap::
cores: 8
hostname: ***
name: OpenJDK 64-Bit Server VM
osArch: x86_64
osName: Mac OS X
vendor: Azul Systems, Inc.
version: 11.0.1+13-LTS
Parameters(files -> median-test): 3.612799 ms
What is going on here?
Edit:
Changing the code as follows atleast does something, but doesn't honor the options. It seems to be running the test a total of 18 times for file 'Median', which is not a sum of 3 + 10.
object MedianMaintenanceBenchmark extends Bench.ForkedTime {
/* configuration */
override def aggregator: Aggregator[Double] = Aggregator.median
private val opts = Context(
exec.minWarmupRuns-> 3,
exec.maxWarmupRuns -> 3,
exec.benchRuns -> 10,
exec.jvmflags -> List("-Xms2g", "-Xmx2g")
)
/* inputs */
private val files: Gen[String] = Gen.enumeration("files")("median-test", "Median")
private val num: Gen[Seq[Int]] = (for (f <- files) yield numbers(f)).cached
/* tests */
performance of "MedianMaintenance" config opts in {
measure method "using heap" in {
using(num) in {
xs => MedianMaintenanceUsingHeaps(xs).medians
}
}
measure method "using red-black BST" in {
using(num) in {
xs => MedianMaintenanceUsingRedBlackTree(xs).medians
}
}
}
private def numbers(filename: String): Seq[Int] = // elided
}