I would like to know what isEqualToArray
actually does...
I have an array with size 160, each containing a dictionary with 11 entries, but I can do the comparison simply based on the first column (contains the date when the row was changed).
Now I can do that with a simple for-cycle:
BOOL different = FALSE;
for (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 I can use the 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
just invokes isEqualTo
for each cell, the for-loop method runs for 1/11 of the time isEqualToArray
does (only need to compare one column instead of 11).
Maybe I'm just too much into optimizing... (I've been at many contests where runtime was limited and I'm feeling the after-effects).
Update
key, the other looks at the whole entry. Third, if you're concerned about performance, you should benchmark it and measure the actual performance.