Re: Speed comparison: compare:, methodForSelector: & CFNumberCompare()
Re: Speed comparison: compare:, methodForSelector: & CFNumberCompare()
- Subject: Re: Speed comparison: compare:, methodForSelector: & CFNumberCompare()
- From: Public Look <email@hidden>
- Date: Sun, 22 Feb 2004 14:48:06 -0500
See
http://www.mulle-kybernetik.com/artikel/Optimization/opti.html
On Feb 22, 2004, at 2:34 PM, Allan Odgaard wrote:
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.
_______________________________________________
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.