Although I am looking through the following NSSet , NSMutableArray , NSFastEnumeration , I cannot find a satisfactory source for the scenario below:
Here NSMutableArray, NSArrayand NSSetcontain the same 10,000,000 objects.
for (NSString *strIn in MutableArray)
{
}
NSLog(@"Time for Mutable Array %d Iteration : %f",ObjectCount,[[NSDate date]timeIntervalSinceDate:startDate]);
startDate = [NSDate date];
for (NSString *strIn in array)
{
}
NSLog(@"Time for NSArray %d Iteration : %f",ObjectCount,[[NSDate date]timeIntervalSinceDate:startDate]);
startDate = [NSDate date];
for (NSString *strIn in Set)
{
}
NSLog(@"Time for Set %d Iteration : %f",ObjectCount,[[NSDate date]timeIntervalSinceDate:startDate]);
The output is as follows:
Time for NSMutableArray10,000,000 Iteration: 0.048785
Time for NSArray10,000,000 Iteration: 0.390537
Time for NSSet10,000,000 Iteration: 4.684203
Why is there such a huge difference between iteration NSSetand NSArraytime.
, .
:
- Set. . , , , . , .