In Kotlin, is there a performance cost to empty methods, or are they ignored?
I ran the following test code, and the cost seems negligible:
fun emptyMethod() {}
for(max in listOf(1000, 10000, 100000, 1000000)){
val start = Instant.now().toEpochMilli()
for(i in 0..max) {
emptyMethod()
}
val millis= Instant.now().toEpochMilli() - start
println("$max iterations: $millis millis.")
}
// 1000 iterations: 0 millis.
// 10000 iterations: 0 millis.
// 100000 iterations: 4 millis.
// 1000000 iterations: 10 millis.
I'm doing validation and I want to use an empty method for documentation purposes (ex. petName.mayBeNull()
) to avoid future comment rot.