SyntheticBenchmarkDataPrinter.kt 1.45 KB
Newer Older
Noric Couderc's avatar
Noric Couderc committed
1
2
package se.lth.cs

3
4
5
import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVPrinter
import java.io.Writer
6
import java.lang.IllegalArgumentException
7
import se.lth.cs.bcgen.*
8

9
10
11
/**
 * An abstract class for printing some data about synthetic benchmarks to CSV.
 */
12
13
abstract class SyntheticBenchmarkDataPrinter(out : Writer,
                                             methodPrintFormat : String) {
14

15
    protected val printer = CSVPrinter(out,
16
17
            CSVFormat.DEFAULT.withFirstRecordAsHeader().withRecordSeparator('\n'))

18
19
20
21
22
23
24
25
26
27
28
29
30
    protected val methodPrintFormat : String = methodPrintFormat

    /**
     * A function which will get the method name in the right output format
     */
    fun getMethodName(name : String): String {
        return when (methodPrintFormat) {
            "JAVA-STANDARD-FORMAT" -> printFunction(name)
            "SYNTHETIC-RUN-FORMAT" -> name
            else -> throw IllegalArgumentException("Format '$methodPrintFormat' was not recognized.")
        }
    }

31
    open fun printToCSV(syntheticBenchmarks: Sequence<BCBenchmarkPackage<*>>) {
32
        printHeader();
33

34
        for (syntheticBenchmark in syntheticBenchmarks) {
35
            System.out.println("Printing benchmark: %s".format(syntheticBenchmark.benchmarkIdentifier))
36
            printBenchmarkRows(syntheticBenchmark)
37
38
39
40
41
        }

        printer.close()
    }

42
    abstract fun printBenchmarkRows(syntheticBenchmark: BCBenchmarkPackage<*>)
43

44
    abstract fun printHeader()
45

46
}