https://kotlinlang.org logo
#announcements
Title
# announcements
m

misko

07/02/2017, 11:40 AM
Can somebody help me with a coroutines question. I was playing with something like shown in this gist: https://gist.github.com/mvucenovic/65359381a578e37558370cdf4e03ed9e. While running this on i7 with 8 cores, compiled to jvm 1.8 as target, coroutine code defined inside 'async' block was ~10x faster then calling any function doing the same thing inside async block (~700ms vs 8000ms). I know measuring performance with main method is terrible idea, but the difference in execution time is enormous in this gist Can somebody explain to me why is that happening?
v

voddan

07/02/2017, 12:53 PM
misko: #coroutines
x

xap4o

07/02/2017, 9:53 PM
Results on my machine: Time with coro plain: 1027 ms Time with coro calling inline function: Time with coro calling suspend function: 35986 ms Time with coro calling normal function: 34813 ms Looks like first loop is replaced by compiler while in all other cases it doesn't. Also consider use JMH to get better results.
m

misko

07/03/2017, 7:40 AM
I've written some basic JMH benchmark to confirm it. I am not well versed in JMH benchmarks so I may have did something wrong, but it produced the same results (I too got as big as X35 differential without JMH, but JMH produced consistently ~X8 times slower results for non plain calls). I'll try to look at the byte code later.. It is strange to me. Tnx for trying it
3 Views