I would like to know what isEqualToArray actually does ...
I have an array of size 160, each of which contains a dictionary with 11 entries, but I can make a comparison simply based on the first column (contains the date the row changed).
Now I can do it with a simple looping loop:
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 isEqualToArray built-in 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 it is assumed that isEqualToArray simply calls isEqualTo for each cell, the for-loop method works in 1/11 of the time isEqualToArray (you only need to compare one column instead of 11).
Perhaps Iβm just optimizing too much ... (I have been to many contests where the execution time is limited and I feel the consequences).
source share