Re: Is NSMutableArray slow?
Re: Is NSMutableArray slow?
- Subject: Re: Is NSMutableArray slow?
- From: David Remahl <email@hidden>
- Date: Thu, 2 Oct 2003 01:02:49 +0200
On 1 okt 2003, at 23.50, Alex Lock wrote:
On Wednesday, October 1, 2003, at 05:11 PM, Chaz McGarvey wrote:
If I had an operation that produced a lot of integers (>100000)
quickly and I wanted to have the integers when the operation
finished, would putting each integer into an NSNumber and then
putting the NSNumber onto the end of an NSMutableArray for each
integer going to be a bottleneck?
Would it be faster to just put the integers into a buffer and expand
the buffer as needed with realloc()?
No idea how fast/slow this would be, but it's easily testable...
Start a timer w/ the minimum resolution (I believe 50ms) and have it
increment a counter on each fire; start this timer right before your
loop.
Stop the timer immediately after your loop, multiply the counter by
the timer increment and you've got a (somewhat accurate) speed
measurement. If you need even more precision, I believe the
OSAnimationTimer from the Omni frameworks (I think it's Omni) is
accurate to within 1ms (designed for animation, but it would work).
Try it both ways, see which is faster. I'm sure there are (much) more
"correct" (mathematical) ways of determining this, but that's my
simple suggestion:)
Good luck!
Alex <email@hidden>
Hmm, the timer (if you are talking about an NSTimer) will only fire if
the run loop is running. Sure, you could do this on a secondary thread,
but a much much simpler and better way would be to check the time just
before and just after the calculation. Something like this:
NSDate *startDate = [NSDate date], endDate;
// do calculation
endDate = [NSDate date];
NSLog(@"Seconds passed: %f", [endDate timeIntervalSinceDate:startDate]);
I can also add that I believe that the practice described in the
initial message _would_ be a bottle neck. But it depends on the
complexity of the "operation" and some other factors, like wether the
number of produced numbers can be known in advance, etc. Since you are
talking about realloc, I guess that is not the case. It is commonly a
good idea to postpone optimizations until the program / algorithm is
working well. Then you can start running profiling tools to determine
the actual bottle necks of your program.
/ Good luck!
// David
_______________________________________________
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.