Even though , I traverse through the following NSSet,NSMutableArray,NSFastEnumeration documentation, I cannot find satisfactory source for the below mentioned scenario:
Here , the NSMutableArray
, NSArray
and NSSet
contains equally 10000000 objects.
for (NSString *strIn in MutableArray) //NSMutableArray
{
// same Implementation
}
NSLog(@"Time for Mutable Array %d Iteration : %f",ObjectCount,[[NSDate date]timeIntervalSinceDate:startDate]);
startDate = [NSDate date];
for (NSString *strIn in array) //NSArray
{
// same Implementation
}
NSLog(@"Time for NSArray %d Iteration : %f",ObjectCount,[[NSDate date]timeIntervalSinceDate:startDate]);
startDate = [NSDate date];
for (NSString *strIn in Set) //NSSet
{
// same Implementation
}
NSLog(@"Time for Set %d Iteration : %f",ObjectCount,[[NSDate date]timeIntervalSinceDate:startDate]);
The output is as follows:
Time for NSMutableArray
10000000 Iteration : 0.048785
Time for NSArray
10000000 Iteration : 0.390537
Time for NSSet
10000000 Iteration : 4.684203
Why there such a huge difference between NSSet
and NSArray
iterating time.
Please be thorough with your answers.
Edit : I've found the actual cause behind the above iteration time it's because of the unequal count in array and Set . I have posted the actual question here. Also , I can post the same here but it seems too undocumented nature for this page and also the reason behind the cause was also deviated. Again, thanks for everyone with their response.