July 2018
Intermediate to advanced
400 pages
12h 14m
English
When the speed of code is an important consideration, Kotlin provides utility functions for profiling code performance: measureNanoTime and measureTimeInMillis. Both functions accept a lambda as their argument and measure the execution speed of the code contained within the lambda. measureNanoTime returns a time in nanoseconds, and measureTimeInMillis returns a time in milliseconds.
Wrap the function to measure in one of the utility functions like so:
val listInNanos = measureNanoTime {
// List functional chain here
}
val sequenceInNanos = measureNanoTime {
// Sequence functional chain here
}
println("List completed in $listInNanos ns")
println("Sequence completed in $sequenceInNanos ns")
Read now
Unlock full access