Nicola
03/30/2023, 1:32 PMval start = System.nanoTime()
execute_my_function()
val duration = System.nanoTime() - start
Would it be ok or are there better ways?mkrussel
03/30/2023, 1:36 PMmeasureTime
, measureTimeInNanos
, measureTimedValue
.
You pass a block into the measure functions and they will return how long it took.Vampire
03/30/2023, 1:36 PMval duration = measureTime {
execute_my_function()
}
Nicola
03/30/2023, 1:39 PMval startTime = System.nanoTime()
val response = execute_my_function()
val duration = System.nanoTime() - startTime
mkrussel
03/30/2023, 1:50 PMDuration
needs an opt in. The measureTimeInNanos
don't. To get a value, use the one that has value in the name.Vampire
03/30/2023, 1:50 PMmeasureTimeMillis
measureTimedValue
mkrussel
03/30/2023, 1:52 PMVampire
03/30/2023, 1:52 PMNicola
03/30/2023, 2:01 PMmeasureTimeMillis
ok thanks a lot!Vampire
03/30/2023, 2:02 PMval result: Int
val timeInMillis = measureTimeMillis {
result = 1
}
nkiesel
03/31/2023, 11:22 PMmeasureTimedValue
: unlikely to change, and nicer to use that breaking up definition and assignment. And if you want to control the potential impact, then create your own wrapper and use that in your code.