Re: Is checking -count worth it?
Re: Is checking -count worth it?
- Subject: Re: Is checking -count worth it?
- From: Quincey Morris <email@hidden>
- Date: Wed, 23 Jul 2008 21:51:10 -0700
On Jul 23, 2008, at 21:15, Steve Cronin wrote:
I have a mutable array, M. I want to remove an object, O, from M; O
might not be in M.
M which is being constantly diminished could become empty.
Is this code worth it?
if ([M count]>0) [M removeObject:O];
OR should I just do
[M remove O];
I assume that I can't write better code than the removeObject's use
of -indexOfObject to determine the existence/location of O.
So there I get 'best performance' for free by just getting out of
the way and letting Cocoa do its thing.
Is the only way to really tell to test?
Or is there a deeper insight that makes the choice clear?
IDK about deeper insights or clear choices but here are 3 possible
answers:
A. Do it whichever way makes you happier.
B. If you need someone to choose for you, consult Wil Shipley's blog
on the subject of brevity:
www.wilshipley.com/blog/2007/05/pimp-my-code-part-14-be-inflexible.html
C. If you can't shrug off performance anxiety, try the following
exercise: See if you can use performance tools to measure the
difference between the two approaches *in the intended application
context*. (Devising an artificial test does you no good, because you
can't reliably apply its results to actual application performance.)
If you can measure a difference, you have your answer. If you can't
measure a difference, you have your answer.
_______________________________________________
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