Re: speed of alloc/init for NSNumber
Re: speed of alloc/init for NSNumber
- Subject: Re: speed of alloc/init for NSNumber
- From: Mark Lilback <email@hidden>
- Date: Mon, 19 Jan 2004 20:54:43 -0800 (PST)
On Jan 19, 2004, at 4:37 PM, John Randolph wrote:
>
I'd certainly recommend these articles for anyone who wants a deeper
>
understanding of the Objective-C runtime. However, let me repeat the
>
standard warning about premature optimization ;-)
While I think this is generally true, I think people emphasize it too
much.
With Cocoa, I use a category on NSNumber that adds
+cachedNumberWithLong: that uses a cache of 0 through 100. Saving the
very common allocation of 0 and 1 seems well worth it to me. 100 was
an arbitrary limit I picked, but even using for 0-10 would be useful.
Same kind of thing for WebObjects applications -- there I define
very frequently used constants like 0, 1, and BigDecimal(0.0).
They are used all over the place in anything I write, so making
constants seems like common sense. But I've had a number of
people question that as premature optimization.
To me, premature optimization is unrolling loops or using assembly
without profiling.
__________________________________________________________________________
"They that can give up essential liberty
Mark J. Lilback to obtain a little temporary safety
<email@hidden> deserve neither liberty or safety."
http://www.lilback.com/ -- Benjamin Franklin
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.