Is there any quick and efficient way of finding max int value in NSArray that consists of NSDictionary objects? I mean sure, I can implement for cycle going through, but I am looking for some API function that’s already tweaked to maximum speed since it’s operating with fairly large amount of data.
[(int, string, string), (int, string, string), (int, string, string)]
I tried working with valueForKeyPath but that really didn’t help me so far, since it works with “ordinary” NSArray objects.
Out of curiosity, I did a little comparison of
valueForKeyPath:vs simple iteration. On my iMac core i7 running OS X 10.8.2, the simple iteration is about twice as fast for an array of 10M elements.Here’s the test program I made:
The results on my machine:
My hypothesis is that the iterative solution is already about as fast as can be for these data structures; there is no getting around having to do the dictionary look-up for each array element. Furthermore, this custom-made iterative solution benefits from knowing that all the
NSNumberobjects haveintvalues; usingisGreaterThan:for comparison slows things down somewhat (but it’s still faster thanvalueForKeyPath:). Any general-purpose library method would almost certainly incur that penalty internally…