"bit stupid" - no, but..

The resulting assembly from:

NSArray testArray = [NSArray alloc] init];
// TODO: fill array with a bunch of NSNumbers (floats)

int i;
float bigNum;
for (i = 0; i < [testArray count]; ++i)
{
        bigNum *= [testArray objectAtIndex:i];
}

Will be a bit slower than the assembly of:

float testArray[SIZEOFARRAY];
// TODO: fill array with a bunch of floats

int i;
float bigNum;
for (i = 0; i < SIZEOFARRAY; ++i)
{
        bigNum *= testArray[i];
}

mainly because the c array and be stuffed into a processor register and there are no object manipulations involved.

However, you never know when Apple will do something tricky with Grand Central Dispatch that will void this argument.

+++++++++++++++++++++++
Rich Collyer - Senior Software Engineer
rcoll...@ironkey.com

IronKey - The World's Most Secure Flash Drive
2008 SC Magazine Readers Choice Award Winner
2008 FOSE Best of Show Winner
2007 GCN Labs Reviewers Choice Winner
+++++++++++++++++++++++




On Dec 17, 2008, at 12:04 PM, Stanislas Krásnaya wrote:

Hello everyone!

I've got a basic question. I'm sure this is a very vast debate, since I've found several answers on the subject, but I'm not satisfied.


I've read that, since we're programming in Objective-C, it's more elegant and reliable to use an NSArray stuffed with NSNumber instead of a classic C array. But what I want to do, it's performing classic calculation, like mean value, variance... etc, on floating point numbers. Typically around 1000 of them.

I know that our computers are fast now, but this doesn't mean that we have to not take care of optimization.


So, since NSArray is designed to store all kinds of NSObject's, and mine will just store some NSNumber's, wouldn't it be a bit stupid to use it?

Thanks in advance.


Stanislas
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/rcollyer %40ironkey.com

This email sent to rcoll...@ironkey.com

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to