Skip to content

Instantly share code, notes, and snippets.

@SecretX33
Created April 30, 2021 20:36
Show Gist options
  • Save SecretX33/ccb69899ea4b3b0e874e26596443a8e5 to your computer and use it in GitHub Desktop.
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
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