== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article By far a direct call is faster, but I was surprised at how > little overhead virtual calls add in relation to the loop counter. I had > to use 10 billion loops or else the difference was undetectable. > I used dmd 1.046 -release -O (the -release is needed to get rid of the > class method checking the invariant every call). > The relative assembly for calling a virtual method is: > mov ECX,[EBX] > mov EAX,EBX > push dword ptr -8[EBP] > call dword ptr 014h[ECX] > and the assembly for calling a delegate is: > push dword ptr -8[EBP] > mov EAX,-010h[EBP] > call EBX > -Steve
Your benchmarks don't show that the direct call is much faster. You had inlining disabled. Was this intentional? If so, it proves my point that most of the overhead from virtual calls comes from the fact that they can't usually be inlined, not because they're virtual.