Threads vs Coroutines - ParallelMap Performance

Опубликовано: 09 Декабрь 2022
на канале: Pairing with Duncan
1,534
46

In the last episode (   • Threads vs Coroutines - ParallelMap P...  ) we implemented a parallelMap operation using streams, raw threads, a threadpool with futures, and coroutines. At first glance the raw threads was quickest, followed by futures, coroutines and then streams.

In this, part 56 of an exploration of where a Test Driven Development implementation of the Gilded Rose stock control system might take us in Kotlin, we investigate the performance of the different functions further, in particular digging down into why coroutines seem to be slow and finding a way to speed them up. We also find a way to use a particular ForkJoinPool to run the streams code, making it as fast as the others (bar the raw threads).

Frankly we only use very rough benchmarks here, with no statistical testing except 'it looks like'. That's OK for gross differences, but is highly suspect when deciding which of two similarly performant approaches is faster. For that check out JMH https://github.com/openjdk/jmh
and you could watch my video from KotlinConf 2017 -    • KotlinConf 2017 - The Cost of Kotlin ...   . [The next episode also has a bit of a better treatment of the benchmarks -    • Threads vs Coroutines - Errors and Ca...  ]

You can see the whole of this series as a playlist
   • All Gilded Rose Episodes  
and the code on GitHub
https://github.com/dmcg/gilded-rose-tdd

If you like this, you’ll probably like the book Java to Kotlin, A Refactoring Guidebook
http://java-to-kotlin.dev
Also if you're going to KotlinConf in April 2023, you could work with Nat Pryce and me at our TDD workshop at KotlinConf https://kotlinconf.com/workshops/

The music in this episode is used with permission from http://toolofgod.com/my-music/royalty... -


Смотрите видео Threads vs Coroutines - ParallelMap Performance онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Pairing with Duncan 09 Декабрь 2022, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,534 раз и оно понравилось 46 людям.