Performance
Let's complete this section by examining the execution times of different communication approaches. Even more importantly, let's compare them with the original single-threaded implementation and with locking methods.
The original single-threaded code needed 75 ms to increment and decrement values. Critical section based synchronization needed 1017 ms, TMonitor implementation took 700 ms, spinlock needed 493 ms, and the fastest parallel implementation so far, TInterlocked, used 407 ms.
In comparison, communication-based approaches are blindingly fast. Both message-based mechanisms needed only 23-24 milliseconds, Synchronize and Queue are even faster with 17 milliseconds, and even the slowest timer- based code needed 36 milliseconds ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access