Speed comparison: compare:, methodForSelector: & CFNumberCompare()
Speed comparison: compare:, methodForSelector: & CFNumberCompare()
- Subject: Speed comparison: compare:, methodForSelector: & CFNumberCompare()
- From: Allan Odgaard <email@hidden>
- Date: Sun, 22 Feb 2004 20:34:18 +0100
Here is an interesting observation. Sorting 100,000 random integers in
different ways (with std::sort):
NSNumbers sending compare: message: 5.1 seconds
NSNumbers using methodForSelector: 4.9 seconds
NSNumbers using CFNumberCompare(): 1.6 seconds
As plain integers: 0.5 seconds
I would assume that Cocoa just calls CFNumberCompare(), but that
doesn't explain then, why using a function pointer to the
implementation of compare: is 4 times slower.
Placing the values in an NSMutableArray and sending
sortUsingSelector:@selector(compare:) 4.6 seconds
sortUsingFunction:CFNumberCompare 1.8 seconds
Presumably NSArray's sort algorithm is slower than std::sort, but it
seems to have a way to message objects faster than my
methodForSelector: (and I gues NSArray wouldn't even be able to use
this one, as it cannot be sure the stored objects are all of the same
type).
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.