To accommodate unit testing and mocking it’s become a common practice to declare methods and properties as virtual. Is there a performance impact of declaring something virtual as supposed to non-virtual?
To accommodate unit testing and mocking it’s become a common practice to declare methods
Share
In general, the difference is that virtual methods are called using a Callvirt Opcode, whereas not virtual methods use a standard Call Opcode. Call Opcodes are definitely faster than Callvirt, but I’ve never ever every found it nearly substantial enough to justify making design decisions based on this.
Premature optimization is the root of all evil.