Re: Accessing array in thread safe way
Re: Accessing array in thread safe way
- Subject: Re: Accessing array in thread safe way
- From: Brian Lambert <email@hidden>
- Date: Thu, 08 Mar 2012 12:51:31 -0800
I should have said, "relatively". As in, good enough for many scenarios
where it will be used infrequently and keeping the code simple makes sense.
Of course, you're right, Charles.
1,000,000 integer increments synchronized by @synchronized, OSSpinLock, and
NSLock:
PerfTimer[95716:403] 1,000,000 @synchronized ++value: [118 ms] [117,813,038
ns]
PerfTimer[95716:403] 1,000,000 OSSpinLock ++value: [8 ms] [8,444,567 ns]
PerfTimer[95716:403] 1,000,000 NSLock ++value: [63 ms] [63,049,168 ns]
A million operations in ~100 ms is fast. A million operations in ~10 ms is
WICKED fast.
Brian
On Thu, Mar 8, 2012 at 12:14 PM, Charles Srstka <email@hidden>wrote:
> On Mar 8, 2012, at 1:19 PM, Brian Lambert wrote:
>
> In many simple scenarios, especially when contention is very low,
> @synchronized will be the best choice because it's trivial to get right and
> high-performance.
>
>
> @synchronized is easy-to-use, for sure, but it is far from
> high-performance.
>
> The first result that Google turns up for benchmarks comparing
> @synchronized, mutexes, and OSSpinLocks shows @synchronized to be almost an
> order of magnitude slower than the competition:
>
> http://perpendiculo.us/?p=133
>
> Charles
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden