I'm working on an app with lots of asynchronous stream processing done using Rx (Reactive Extensions) - IObservable<T> method. We were discussing the other day whether to replace the implementations which only return a single data item via the Rx stream with the more standard TPL (Task Parallel Library) Task<T> method.
We came to the conclusion we wouldn't make the switch for a couple reasons, firstly keeping the code consistency, we're using Rx everywhere for async so why change; and secondly with a possibly more important reason because performance isn't an issue (at the moment).
Then I thought....
What's the performance difference between IObservable<T> and Task <T> for a single async invocation?
A simple console app should do, running IObservable<T> vs Task<T> and the quickest wins - reminds me of Celebrity Deathmatch...
Firstly we need something to test, calculating the first 100 primes:
All I need now is a couple of methods for each async implementation...
firstly IObservable<T>:
secondly Task<T>:
All I need now is a test program:
So which test method is quicker?
The answer is Task<T>, in facts it quicker by a factor of greater than 10:
Even if I swap the order Task<T> out performs:
A simple console app should do, running IObservable<T> vs Task<T> and the quickest wins - reminds me of Celebrity Deathmatch...
Firstly we need something to test, calculating the first 100 primes:
All I need now is a couple of methods for each async implementation...
firstly IObservable<T>:
secondly Task<T>:
All I need now is a test program:
So which test method is quicker?
The answer is Task<T>, in facts it quicker by a factor of greater than 10:
Even if I swap the order Task<T> out performs: