Hey guys. I am using coroutines to run several lon...
# announcements
d
Hey guys. I am using coroutines to run several long tasks in parallel, and I would like to time each of the tasks, but considering only the time that the coroutine has actually been executed (that is, excluding the time it was suspended). I haven’t been able to find any info on this yet. Anyone have a suggestion?
a
Can you use this around the code that's excuted inside the coroutine? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.system/measure-time-millis.html I'm no coroutine expert, but this should do the timing thing you want.
d
I’ll try it and let you know. Thanks!
I looked at the implementation and it’s what I am doing right now, calling System.currentTime… at the beginning and end. I’m not sure if this would give me the correct time for the computation.
I am currently running many async blocks with NON-suspend function in them
Copy code
val value = async { doComputationAndGetResults() };
runBlocking {
  val duration = value.await().duration
}

...
fun doComputationAndGetResults() {
   val startTime = ...
   compute()
   val endTime = ...

   return Result(..., endTime - startTime)
}
Do you have any idea if the compute() function, which is not a suspend function would be suspended in the middle of the computation? If it would, then the interval I get by subtracting the two values would be invalid
p
If compute() is not a
suspend
function, it cannot be suspended so the computation should be fine
BTW there's #C1CFAFJSK
d
thanks, I did not know about the channel 🙂