D vs C++ - Where are the benchmarks?
Jonathan M Davis
jmdavisProg at gmx.com
Thu Jul 4 12:45:24 PDT 2013
On Thursday, July 04, 2013 21:26:21 Mehrdad wrote:
> On Wednesday, 3 July 2013 at 07:12:54 UTC, Joseph Rushton
>
> Wakeling wrote:
> > On 07/03/2013 05:13 AM, Mehrdad wrote:
> >> That doesn't mean D is "faster". It just means it's less
> >> painful to get the same
> >> performance.
> >
> > That would be ... kind of the point. If we didn't care about
> > the pain, we'd all
> > be programming using assembly. Or butterflies:
> > https://xkcd.com/378/
> >
> > But faster performance with less pain and more safety? Yes
> > please. :-)
>
> Not really. For example, no matter how much C++ code you feel
> like writing, it'll be _impossible_ for you to replicate the
> behavior of a GC in C++.
>
> So it's not a matter of how much pain you're willing to go
> through -- it's literally a matter of language capabilities.
It's perfectly possible to implement a GC - even D's GC - in C++. You could
even make it work with new by overriding the global new (as stupid a thing as
that would arguably be). Given enough time and effort, you can do almost
anything in C++ that you can do in D. There are some things relating to type
introspection, code generation, and CTFE which you can't do directly in C++,
but even then, you could just add something to your build process which
generated the C++ code that you wanted. So, while you can't do that stuff
directly in the language, you can still generate the C++ code that it would
have generated if C++ had those capabilities.
So, given enough time and effort, you can _always_ make C++ match D for speed.
Given enough time and effort, you can _always_ make D match C++ for speed. It's
just a question of how much time and effort you want to go to and how much of a
pain it is to do so.
The real question is how idiomatic C++ compares with idiomatic D for speed,
and how much programming effort is required to make one match the other when
it's slower.
In general, idiomatic D should be comparable to idiomatic C++ for speed, and
where it isn't, it should be fairly easy to write the equivalent of the
idiomatic C++ code and get the same efficiency. However, it's frequently the
case that writing the C++ equivalent of idiomatic D code is a royal pain, so
it's unlikely that anyone is going to write their C++ code in a manner which
will beat such D code. Most anything involving a lot of slicing is likely to
fall into that category.
But ultimately, C++ and D are both systems languages and provide enough
capabilities that given enough time and effort neither can possibly beat the
other for speed.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list