Re: garbage collection and NSConnection
Re: garbage collection and NSConnection
- Subject: Re: garbage collection and NSConnection
- From: Marcel Weiher <email@hidden>
- Date: Fri, 11 Jul 2008 23:25:16 -0700
On Jul 11, 2008, at 12:53 , Michael Ash wrote:
Seems that NSString and NSMutableString are just faster at everything.
In all cases, the cost of an extra retain/release for them is still
roughly 50% of the cost of an alloc/init/retain. Here are my raw
numbers, times in nanoseconds:
[timings snipped]
I have no explanation as to why NSMutableString is so much slower at
everything.
I do ;-)
They both end up creating an instance of NSCFString, so
this is puzzling. But there you are.
These sorts of tests can be tricky to get right: of the two, only the
NSMutableString test is creating strings for you, your NSString test
is just returning the same empty+constant string over and over (you
can verify this by printing the object pointer). You can control for
this, for example by using -initWithCString: with a buffer whose
contents change slightly each time.
These are the numbers I get:
NSMutableString alloc+init(WithCString:) + release(/dealloc) : 1246
nanoseconds
NSMutableString alloc+init(WithCString:) + release(/dealloc) +retain/
release: 1365 nanoseconds
NSString alloc+init(WithCString:) + release(/dealloc) : 418
nanoseconds
NSString alloc+init(WithCString:) + release(/dealloc) +retain/
release: 527 nanoseconds
In both cases, the extra retain/release costs around 110ns, so
allocation is 4x to 10x slower. (I have to admit the 4x surprises me
a little bit, in my experience that value was higher).
The reason NSMutableString is slower is that it needs to allocate an
extra buffer. NSString is pretty heavily optimized, it takes just as
long to allocate as does an empty NSObject:
NSObject alloc+init+release(/dealloc): 417 ns
But of course the retain/release for NSObject is much more expensive:
NSObject alloc+init+release(/dealloc) + retain/release: 740 ns
NSObject alloc+init+release(/dealloc) + 2x retain/release: 1026 ns
So as I said: (a) object allocation slowest (b) out-of-band retain
count slow (c) inline retain count much faster than either.
Regards,
Marcel
_______________________________________________
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