romaonthego romaonthego - 4 months ago 17
iOS Question

performSelector vs direct call performace

Is there any significant difference in performance when you call

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


vs

[someObject testMethod:anotherObject];


?

Thanks!

Answer

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.