Last active
April 29, 2024 20:55
-
-
Save valentineRutto/25e49450cdea20212e31cbb5ef342d69 to your computer and use it in GitHub Desktop.
Calculate function execution time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.time.measureTime | |
import kotlin.time.measureTimedValue | |
fun main() { | |
val executionTime = measureTime{ | |
val isFlooding= predictFloodingInNairobi(0.35,7000.0) | |
println("Will Nairobi Flood? $isFlooding ") | |
} | |
println("TimeTaken in millis: $executionTime ") | |
val (value, timeTaken) = measureTimedValue{ | |
predictFloodingInNairobi(0.35,7000.0) | |
} | |
println("Will Nairobi Flood: $value, ") | |
println("TimeTaken in microseconds: $timeTaken, ") | |
} | |
private fun predictFloodingInNairobi(amountOfRain: Double, areaInSquareMeters: Double): Boolean { | |
val rainfallThresholdInMillimeters = 50.0 | |
val areaThreshold =1000.0 | |
val rainfallInMillimeters = amountOfRain * 1000.0 | |
return rainfallInMillimeters > rainfallThresholdInMillimeters && areaInSquareMeters > areaThreshold | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment