views:

67

answers:

3

Situation:
I have a DAY structure. The DAY structure has three variables or attributes: a Date (NSString*), a Temperature (float), and a Rainfall (float).

Problem:
I will be iterating through an array of about 5000 DAY structures and graphing a portion of these onto the screen of the iPhone device using OpenGL.

Question:
As far as drawing performance, which is better? I could simply create an NSMutableArray of DAY structures (NSObjects) and iterate on the array on each draw call -- which I think would be hard on the CPU. Or, I could instead manually manage three different C-Arrays -- One for the Date String (2-Dimensional), One for the temperature (1-Dimensional) and One for the Rainfall (1-Dimensional). I could keep track of the current Day by referencing the current index of the iterated C-Arrays.

+2  A: 

Try both and profile.

There's really no other answer, especially since we can never know your exact context for sure. Every app works differently.

If they both give the same performance, choose the one that is the easiest for you to use and is the most readable.

Shaggy Frog
+2  A: 

If it's not a lot of work, always go with the convenient solution and only optimize when the code proves to be a bottleneck. And if you were going to write a big chunk of code that would take a long time to rewrite into a more optimized version, do a simple test case and profile.

zoul
+1 for the high-level-api before low-leverl-stuff.
bddckr
+3  A: 

Why are you keeping a date in an NSString object instead of an NSDate object?

NSResponder
What NSResponder Said. Given that you have strings representing Dates, there is quite likely a far bigger performance issue in your app that anything related to arrays. Quantify, then optimize.
bbum