• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Performance of calculation on float point numbers in a array • NSNumber in NSArray, or classic C array?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Performance of calculation on float point numbers in a array • NSNumber in NSArray, or classic C array?


  • Subject: Re: Performance of calculation on float point numbers in a array • NSNumber in NSArray, or classic C array?
  • From: Quincey Morris <email@hidden>
  • Date: Thu, 18 Dec 2008 11:01:30 -0800

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

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?

There's nothing inelegant about using a classic C array for this. You can allocate the memory for the array with malloc, for a classic- classic solution, or allocate the memory as a NSData object for a classic-hybrid solution. If you only want to do calculations with the numbers, this seems like the obvious approach.


There's also nothing wrong with using a NSArray of NSNumber objects. You might consider this solution if you think there might be side benefits, or if it is easier to code somehow. For example, if you have a NSArray of NSNumber objects, it's very easy to add a NSTableView to your interface that displays them.

It's unlikely that calculating mean, variance, etc on 1000 NSNumber objects is going to be a performance issue, unless you're doing these calculations over and over.

So, choose the approach that gives the clearest, most maintainable code, then (if necessary) measure the performance to see whether you need to optimize your approach.

FWIW.

_______________________________________________

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


  • Follow-Ups:
    • Re: Performance of calculation on float point numbers in a array • NSNumber in NSArray, or classic C array?
      • From: Stanislas Krásnaya <email@hidden>
References: 
 >Performance of calculation on float point numbers in a array • NSNumber in NSArray, or classic C array? (From: Stanislas Krásnaya <email@hidden>)

  • Prev by Date: Re: -[NSURLConnection cancel] doesn't release its delegate?
  • Next by Date: Re: garbage collection memory leak
  • Previous by thread: Re: Performance of calculation on float point numbers in a array • NSNumber in NSArray, or classic C array?
  • Next by thread: Re: Performance of calculation on float point numbers in a array • NSNumber in NSArray, or classic C array?
  • Index(es):
    • Date
    • Thread