JMHProcessor.kt 1.83 KB
Newer Older
1
2
3
4
5
6
7
package se.lth.cs

import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVParser
import java.io.File
import java.io.FileReader
import java.io.Reader
8
import java.lang.Exception
9
10

class JMHProcessor {
11
    fun processFile(filename: String): List<List<String?>> {
12
13
14
        return processReader(FileReader(File(filename)))
    }

15
    fun processReader(reader: Reader): List<List<String?>> {
16
17
18
19
        var parser = CSVParser(reader, CSVFormat.DEFAULT.withFirstRecordAsHeader())
        // We are grouping the parameters by any parameter excep the data structure name (which we want)

        val columns = parser.headerMap.keys
20
        // These are the columns we want to use for group by
21
22
23
        val selectedColumns = columns
                .filter { it -> it.contains("Param") }
                .minus("Param: datastructureName")
24
                .plus("Benchmark")
25
26
27
28
29
30

        val seedsToRecords = parser.records.groupBy { record ->
            selectedColumns.map { column -> record.get(column) }
        }

        return seedsToRecords.values.map { records ->
Noric Couderc's avatar
Noric Couderc committed
31
            val interfaceName = records[0].get("Benchmark").let { processBenchmarkName(it) }
32
33
34
            val seed = records[0].get("Param: seed")
            val size = records[0].get("Param: applicationSize")
            val bestScore = records.maxBy { it.get("Score") }
Noric Couderc's avatar
Noric Couderc committed
35
            listOf(interfaceName, seed, size, bestScore?.get("Param: datastructureName"))
36
37
        }
    }
38
39
40
41
42
43
44
45
46
47
48

    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
    }
49
}