运行时派发机制

  • Unlike C++, it is not necessary to designate that a method is virtual in Swift. The compiler will work out which of the following to use: 

    (the performance metrics of course depend on hardware)

    • Inline the method : 0 ns
    • Static dispatch: < 1.1ns
    • Virtual dispatch 1.1ns (like Java, C# or C++ when designated). 
    • Dynamic Dispatch 4.9ns (like Objective-C). 

    Objective-C of course always uses the latter.

猜你喜欢

转载自www.cnblogs.com/feng9exe/p/9460294.html