Stanislas:

> 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.

  I faced this very same situation with a scientific data mining and
visualization application. In my case, it was a permutation test
against a whole lot of doubles (for reasons of precision). When
dealing with any level of precision, you may have to "roll the dice"
10,000 times per comparison or more. Because the application takes
advantage of Core Data and (to an extent Cocoa Bindings) I first
implemented this using NS[Mutable]Arrays of NSNumbers.

  It did not perform well. :-)

  The standard test set I used took literally around a minute to run.
Unacceptable for a "explore as you go" visualization UI. I then asked
myself why I felt everything had to be shoehorned into Cocoa /
Objective-C ... of course I was embarrassed and had no explanation to
offer myself. After I'd thoroughly chastised myself for being so
ridiculous, I re-implemented the test by extracting the necessary
values into a C array of doubles (and another of randomized vector
indices) then doing the calculations.

  First, I'll say that this felt wasteful because "they're already
neatly-packaged objects - won't performance suffer copying values back
and forth like that?" Once I got over that and actually reasoned it
out, I informed myself that the answer was, of course, "no, because
comparatively speaking, copying the values around is nothing next to
100,000 iterations and many more sufficiently-random-number
generations to shuffle the vectors".

  To which I replied, "Oh." :-)

  All told, the minute-long permutation test was reduced to about two
seconds. Wow.

  I hope this is helpful.

--
I.S.
_______________________________________________

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