import org.openjdk.jmh.annotations.Benchmark interface Extension<ELEMENT>{ fun ELEMENT.prettyPrint() { println("Default pretty " + this) } } object StringListExtension : Extension<String> fun <T> someFrameWorkFunction(parameter : T, extensionProvider: Extension<T>) { with(extensionProvider) { parameter.prettyPrint() } } @Benchmark fun extension() { someFrameWorkFunction("asd", StringListExtension) } fun String.prettyPrint() { println("Default pretty " + this) } @Benchmark fun baseline() { "asd".prettyPrint() }
Surprising results again:
Benchmark Mode Cnt Score Error Units BenchmarkRunner.benchmarkBaseline thrpt 200 269087.160 ± 17915.393 ops/s BenchmarkRunner.benchmarkExtension thrpt 200 329648.131 ± 19646.005 ops/s
Once again, the opposite of my expectations.
Keine Kommentare:
Kommentar veröffentlichen