D 50% slower than C++. What I'm doing wrong?
Jonathan M Davis
jmdavisProg at gmx.com
Sat Apr 14 19:31:40 PDT 2012
On Sunday, April 15, 2012 04:21:09 Joseph Rushton Wakeling wrote:
> On 14/04/12 23:03, q66 wrote:
> > He also uses a class. And -noboundscheck should be automatically induced
> > by
> > -release.
>
> ... but the methods are marked as final -- shouldn't that substantially
> reduce any speed hit from using class instead of struct?
In theory. If they don't override anything, then that signals to the compiler
that they don't need to be virtual, in which case, they _shouldn't_ be
virtual, but that's up to the compiler to optimize, and I don't know how good
it is about that right now. Certainly, if you had code like
class C
{
final int foo() { return 42;}
}
and benchmarking showed that it was the same speed as
class C
{
int foo() { return 42;}
}
when compiled with -O and -inline, then I'd submit a bug report (maybe an
enhancement request?) on the compiler failing to make final functions non-
virtual.
Also, if the function is doing enough work, then whether it's virtual or not
really doesn't make any difference, because the function itself costs so much
more than the extra cost of the virtual function call.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list