What are the performance implications of marking methods / properties as virtual?

后端 未结 7 1258
别那么骄傲
别那么骄傲 2020-12-04 14:06

Question is as stated in the title: What are the performance implications of marking methods / properties as virtual?

Note - I\'m assuming the virtual methods will <

相关标签:
7条回答
  • 2020-12-04 14:51

    I ran this test in C++. A virtual function call takes (on a 3ghz PowerPC) between 7-20 nanoseconds longer than a direct function call. That means it really only matters for functions you plan on calling a million times per second, or for functions that are so small that the overhead may be larger than the function itself. (For example, making accessor functions virtual out of blind habit is probably unwise.)

    I haven't run my test in C#, but I expect that the difference will be even less there, since nearly every operation in the CLR involves an indirect anyway.

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