D vs C++ - Where are the benchmarks?

Jonathan M Davis jmdavisProg at gmx.com
Sun Jun 30 19:53:05 PDT 2013


On Monday, July 01, 2013 04:37:43 Mehrdad wrote:
> On Sunday, 30 June 2013 at 20:49:28 UTC, Peter Alexander wrote:
> > sometimes faster
> 
> Would love an example that demonstrates it!

Anything involving taking a lot of substrings is likely to be faster in D 
thanks to slices (which is one of the main reasons that Tango's xml parser is 
so lightning fast). You could write the same code in C++, but it's harder, 
because slices aren't built-in, and you have no GC, probably forcing you to 
create your own string type that supports slices and does reference counting 
if you want a similar effect. However, you do have to be somewhat careful with 
string processing and Phobos functions, because you could end up doing more 
decoding than you might want, which would slow down the code (as Phobos 
strives to be Unicode correct by default, whereas C++'s STL doesn't). But 
anything which heavily uses slicing stands a good chance of creaming C++ code 
doing the same task. So, in general, well-written parsers written in D should 
beat well-written parsers written in C++.

- Jonathan M Davis


More information about the Digitalmars-d mailing list