Cost of message dispatch in Objective-C

前端 未结 2 2088
执念已碎
执念已碎 2020-12-19 13:33

I\'m curious to know about the cost of message dispatch in Objective-C in various situations. Particularly I want to guide my choice of program design so I\'m not tempted to

2条回答
  •  盖世英雄少女心
    2020-12-19 13:51

    Objective C messages are very fast. The speed is comparable to C++ virtual method calls, although not quite as fast. Avoiding message passing is definitely premature optimization. You might not want to do a lot of it in an inner loop, but the algorithms you choose and other factors will have a much bigger factor on how fast your code is. If it is too slow, use a profiler and go from there.

提交回复
热议问题