C#: Virtual Function invocation is even faster than a delegate invocation?

后端 未结 7 2149
梦谈多话
梦谈多话 2021-02-05 13:02

It just happens to me about one code design question. Say, I have one \"template\" method that invokes some functions that may \"alter\". A intuitive design is to follow \"Templ

相关标签:
7条回答
  • 2021-02-05 13:54

    virtual overrides have some sort of redirection table or something which is hardcoded and fully optimized at compile time. It's set in stone, very fast.

    Delegates are dynamic which will always have an overhead and they seem to be objects too so that adds up.

    You shouldn't worry about these small performance differences (unless developing performance critical software for the military), for most purposes good code structure wins over optimization.

    0 讨论(0)
提交回复
热议问题