On 9 Feb 2014, at 14:57, Kyle Sluder <k...@ksluder.com> wrote: > On Sat, Feb 8, 2014, at 11:35 PM, Gerriet M. Denkmann wrote: >> But using two threads takes much longer than just using one! >> How could this happen? > > Because now you've got two CPUs fighting over one cache line? > > Optimization is hard. "Throw more threads at it" is not a panacea.
Well, I am realising this right now. That's also why I build this test app. It gets even stranger: Neither counting nor modifying is the problem: # (no count) (no modify) 999888777 bytes in 1 ... 5 threads 1 0.9173 2 0.4721 3 0.3242 4 0.3694 5 0.3058 # count (no modify) 999888777 bytes in 1 ... 5 threads 1 2.205 2 1.327 3 0.9872 4 1.063 5 0.7883 # (no count) modify 999888777 bytes in 1 ... 5 threads 1 1.227 2 0.6331 3 0.4341 4 0.4799 5 0.3612 But doing BOTH in the same loop is: # count modify 999888777 bytes in 1 ... 5 threads 1 2.258 2 2.867 3 3.596 4 4.276 5 3.149 The real app (which I am trying to optimise) has actually two loops: one is counting, the other one is modifying. Which seems to be good news. But I would really like to understand what I should do. Trial and error (or blindly groping in the mist) is not really my preferred way of working. Kind regards, Gerriet. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com