While testing the performance of a lock free data structure, I've encountered some strange performance numbers.
C = 1: Avg time for 20000000 operations = 565.572033ms, ops/sec = 35362427.477032
C = 2: Avg time for 20000000 operations = 1.704945s, ops/sec = 11730583.684518
C = 3: Avg time for 20000000 operations = 1.306999668s, ops/sec = 15302222.708751
C = 4: Avg time for 20000000 operations = 298.103992ms, ops/sec = 67090681.563231
This is on a late model MacBook Air (4-core i7).
When I run this in an 8-core VM on a different system I get similar results and values of C>4 show around 250-300ms.
Can anyone shed some light on why the performance drops for 2 and 3 threads and then doubles (compared to 1 thread) for 4 or more threads?
I was expecting the performance to remain steady or decline slightly. As more threads try and perform the same operation I expected there to be more atomic operation retries and a decline in performance, but the sudden jump with 4 or more threads is surprising.