FROM : Sherm Pendley
DATE : Wed Nov 20 05:00:36 2002
On Monday, November 18, 2002, at 02:04 PM, Buzz Andersen wrote:
> My question is: is there a good way for me to give the CPU a break and
> make the computer more responsive during this loop without compromising
> performance significantly?
Are you sending messages inside of this loop? If so, you could eliminate
some overhead from that, by using NSObject's methodForSelector: to get a
direct pointer to the implementation (that is, an IMP) for the method.
From the example, you'd replace this:
while ( ![target isEqual: someObject] ) {
...
}
with this:
BOOL (*test)(id, SEL, id);
test = (BOOL (*)(id, SEL, id))([target methodForSelector:
@selector(isEqual:)];
while ( !test(target, @selector(isEqual:), someObject) ) {
...
}
As you can see, the replacement is a bit harder to read. I'd benchmark
both alternatives, to be sure that the added performance is enough to
justify the loss in maintainability.
sherm--
If you listen to a UNIX shell, can you hear the C?
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
DATE : Wed Nov 20 05:00:36 2002
On Monday, November 18, 2002, at 02:04 PM, Buzz Andersen wrote:
> My question is: is there a good way for me to give the CPU a break and
> make the computer more responsive during this loop without compromising
> performance significantly?
Are you sending messages inside of this loop? If so, you could eliminate
some overhead from that, by using NSObject's methodForSelector: to get a
direct pointer to the implementation (that is, an IMP) for the method.
From the example, you'd replace this:
while ( ![target isEqual: someObject] ) {
...
}
with this:
BOOL (*test)(id, SEL, id);
test = (BOOL (*)(id, SEL, id))([target methodForSelector:
@selector(isEqual:)];
while ( !test(target, @selector(isEqual:), someObject) ) {
...
}
As you can see, the replacement is a bit harder to read. I'd benchmark
both alternatives, to be sure that the added performance is enough to
justify the loss in maintainability.
sherm--
If you listen to a UNIX shell, can you hear the C?
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
| Related mails | Author | Date |
|---|---|---|
| Buzz Andersen | Nov 18, 20:04 | |
| Buzz Andersen | Nov 18, 23:09 | |
| Kevin Elliott | Nov 19, 18:33 | |
| Alex Rice | Nov 20, 02:05 | |
| Sherm Pendley | Nov 20, 05:00 | |
| Ryan Stevens | Nov 20, 16:57 | |
| Buzz Andersen | Nov 21, 05:32 | |
| Ondra Cada | Nov 21, 15:02 |






Cocoa mail archive

