performSelector与直接呼叫性能

rom*_*ego 8 iphone cocoa objective-c ios

打电话时,性能是否有任何显着差异

[someObject performSelector:@selector(testMethod:) withObject:anotherObject];
Run Code Online (Sandbox Code Playgroud)

VS

[someObject testMethod:anotherObject];
Run Code Online (Sandbox Code Playgroud)

bbu*_*bum 8

第一种情况导致额外调用objc_msgSend(),这在第二种情况下是不必要的.

除非你尽可能快地调用所述方法并且你没有做任何重要的工作,否则性能差异不大可能是远程重要的testMethod:.

即使您测量实际性能问题,除非它不担心.