Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

performSelector vs direct call performance

Is there any significant difference in performance when you call

[someObject performSelector:@selector(testMethod:) withObject:anotherObject];

vs

[someObject testMethod:anotherObject];

?

like image 207
romaonthego Avatar asked Jul 28 '11 01:07

romaonthego


People also ask

What is performSelector?

Sends a specified message to the receiver and returns the result of the message.

What is performSelector in swift?

Swift is statically typed so the performSelector: methods are to fall by the wayside. Instead, use GCD to dispatch a suitable block to the relevant queue — in this case it'll presumably be the main queue since it looks like you're doing UIKit work.


1 Answers

The first causes an extra call to objc_msgSend() that isn't necessary in the second case.

The performance difference is unlikely to remotely matter unless you are calling said method as quickly as you possibly can many 10s of thousands of times and you aren't doing any significant work in testMethod:.

I.e. don't worry about it unless you measure an actual performance problem.

like image 92
bbum Avatar answered Sep 22 '22 00:09

bbum