Commit 5bce2c09 authored by Noric Couderc's avatar Noric Couderc
Browse files

Added tests and code to process Benchmark names

The benchmark names generated by JMH are really long, so they are shortened to
the name of the interface of the class used during the benchmarking.
parent 7d1d76b8
......@@ -5,6 +5,7 @@ import org.apache.commons.csv.CSVParser
import java.io.File
import java.io.FileReader
import java.io.Reader
import java.lang.Exception
class JMHProcessor {
fun processFile(filename: String): List<List<String?>> {
......@@ -33,4 +34,15 @@ class JMHProcessor {
listOf(seed, size, bestScore?.get("Param: datastructureName"))
}
}
class JMHProcessorException(override val message: String?) : Exception(message) { }
fun processBenchmarkName(benchmark : String) : String {
val options = listOf("List", "Map", "Set")
val name = benchmark.findAnyOf(options)?.second
if (name.isNullOrBlank()) {
throw JMHProcessorException("Benchmark name does not contain any of $options")
}
return name
}
}
......@@ -151,4 +151,29 @@ class JMHProcessorTest {
result
)
}
@Test(expected=JMHProcessor.JMHProcessorException::class)
fun testBenchmarkProcessingEmpty() {
Assert.assertEquals("", processor!!.processBenchmarkName(""))
}
@Test
fun testBenchmarkProcessingMap() {
val bench =
"\"se.lth.cs.jmh.MapApplicationBenchmark.MapApplicationBenchmark\""
Assert.assertEquals("Map", processor!!.processBenchmarkName(bench))
}
@Test
fun testBenchmarkProcessingList() {
val bench =
"\"se.lth.cs.jmh.ListApplicationBenchmark.ListApplicationBenchmark\""
Assert.assertEquals("List", processor!!.processBenchmarkName(bench))
}
@Test
fun testBenchmarkProcessingSet() {
val bench =
"\"se.lth.cs.jmh.SetApplicationBenchmark.SetApplicationBenchmark\""
Assert.assertEquals("Set", processor!!.processBenchmarkName(bench))
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment