Kroppeb
12/03/2022, 4:59 PMxxfast
12/03/2022, 11:54 PMkotlinx.benchmark
on my aoc project as they did on this stream. Do i need to wrap all my functions in a class just for it to be benchmarked? Can I not benchmark top-level functions?maiatoday
12/04/2022, 7:21 PM@State(Scope.Benchmark)
@Fork(1)
@Warmup(iterations = 0)
@Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
open class DayBenchmark{
private var input: List<String> = emptyList()
private val day = Day04
@Setup
fun setUp() {
input = readInput(day.number, "Day")
}
@Benchmark
fun part1(): Long = day.part1(input) // I think you could call any function here, even a top level one
@Benchmark
fun part2(): Long = day.part2(input)
@Benchmark
fun part1Alternative(): Long = day.part1Set(input)
@Benchmark
fun part2Alternative(): Long = day.part2Set(input)
}