Stop Using System.currentTimeMillis() for Benchmarking: Kotlin’s measureTimedValue and Duration API
The Old Way: Manual Time Measurement If you’ve ever benchmarked a function in Kotlin or Android, you’ve probably written something like this: val start = System.currentTimeMillis() val result = doExpensiveWork() val elapsed = System.currentTimeMillis() – start Log.d(“Perf”, “doExpensiveWork took ${elapsed}ms, result=$result”) It works, but it’s noisy. You need three lines just to time one call, […]
