Performance Impact of Virtual Methods

For unit testing and bullying, it has become common practice to declare methods and properties virtual. Does performance impact occur when declaring virtual as supposed non-virtual?

+6
source share
3 answers

In general, the difference is that virtual methods are called using Opcode Callvirt, while non-virtual methods use the standard Opcode call. Opcodes are certainly faster than Callvirt, but I have never seen them nearly significant enough to warrant decision making based on this.

Premature optimization is the root of all evil.

+9
source

No, not at all.

This is not what you will notice.

+1
source

I do not know the specifics, but I know that you do not need to worry about this for 99% of applications.

btw - If you choose Mock interfaces instead of classes, you won't need virtual methods.

Good luck Tom

+1
source

Source: https://habr.com/ru/post/912014/


All Articles