objective c - Optimizing this for loop -
i'm running time profiler in instruments. i've simplified code much can boil downwards exact issue. line of code within loop has checkinstring =[_formatter stringfromdate:[checkinarraycopy objectatindex:i]]; taking on 90% of processing time. ideas on how can optimize code?
nsdateformatter *format = [[nsdateformatter alloc]init]; [format settimezone:[nstimezone timezonewithabbreviation:@"gmt"]]; [format setdateformat:@"mm/dd/yyyy"]; nsstring *checkinstring; (int x=0; x<100; x++) { (int i=0; i<checkinarray.count; i++) { //checkinarray nsmutablearray of nsdates, 100 objects within checkinstring =[_formatter stringfromdate:[checkinarray objectatindex:i]]; //**90% of processing time } }
to honest, think big improvements going algorithmic changes beyond scope of can practically suggest here (e.g. cut down amount of looping need do, or eliminate need dates' strings).
there couple of micro-optimizations do, though don't expect them create drastic difference. basically, can cut down number of message sends using imp caching , nsarray's enumeration methods instead of c for-loop, should give little boost.
nsdateformatter *format = [[nsdateformatter alloc]init]; [format settimezone:[nstimezone timezonewithabbreviation:@"gmt"]]; [format setdateformat:@"mm/dd/yyyy"]; __block nsstring *checkinstring; id (*stringfromdateimp)(id, sel, id) = [_formatter methodforselector:@selector(stringfromdate:)]; (int x=0; x<100; x++) { [checkinarray enumerateobjectsusingblock:^(nsdate *date, nsuinteger i, bool *stop) { //checkinarray nsmutablearray of nsdates, 100 objects within checkinstring = stringfromdateimp(_formatter, @selector(stringfromdate:), date); }]; }
(written in browser, caveat compilor.)
objective-c xcode optimization for-loop nsdateformatter
No comments:
Post a Comment