ios - Which one is faster? for-loop or isEqualToArray -
i know isequaltoarray
does...
i have array size 160, each containing dictionary 11 entries, can comparison based on first column (contains date when row changed).
now can simple for-cycle:
bool different = false; (int index = 0 ; index < [newinfo count] ; ++index) if (![[[oldinfo objectatindex:index] objectforkey:@"update"] isequal:[[newinfo objectatindex:index] objectforkey:@"update"]]) { different = true; break; } if (different) { } else nslog(@"contact information hasn't been updated yet");
or can use built-in isequaltoarray method:
if ([oldinfo isequaltoarray:newinfo]) nslog(@"contact information hasn't been updated yet"); else { nslog(@"contact information has been updated, saving new contact information"); [newinfo writetofile:path atomically:yes]; }
now, if assuming isequaltoarray
invokes isequalto
each cell, for-loop method runs 1/11 of time isequaltoarray
(only need compare 1 column instead of 11).
maybe i'm optimizing... (i've been @ many contests runtime limited , i'm feeling after-effects).
when know both objects arrays, isequalto<class>
method faster way check equality loop.
isequalto<class>
used provide specific checks equality.so isequaltoarray:
checks arrays contain equal number of objects.
so per knowledge can isequaltoarray
better option when know 2 objects arrays.
Comments
Post a Comment