Created
April 30, 2021 20:36
-
-
Save SecretX33/ccb69899ea4b3b0e874e26596443a8e5 to your computer and use it in GitHub Desktop.
Kotlin bench used to calculate how many times does a function take to run, on average
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
inline fun bench(run: () -> Unit) = (0..1_000_000).map { | |
measureTime(run).inMicroseconds | |
}.average() | |
bench { | |
// first code | |
}.toString() + "us" | |
bench { | |
// second code | |
}.toString() + "us" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment