D vs C++ - Where are the benchmarks?

Jonathan M Davis jmdavisProg at gmx.com
Sun Jun 30 23:37:48 PDT 2013


On Monday, July 01, 2013 08:28:54 monarch_dodra wrote:
> On Monday, 1 July 2013 at 02:53:24 UTC, Jonathan M Davis wrote:
> > 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.
> > 
> > - Jonathan M Davis
> 
> Well... in "C++", a slice is called an iterator pair. If you just:
> typedef std::pair<std::string::const_iterator, const_itrator>
> string_slice;
> 
> Then there is no reason you can't do it... The only "problem" is
> that it is not a standard semantic in C++, so nobody ever thinks
> about doing this, and much less actually ever does it. There is a
> *little* bit of barrier to entry too.
> 
> I've done this once about two years ago (before I knew about D)
> because I needed a "subview" of a vector. My typedef's name was
> "shallow_vector". It was a fun experience given I didn't know
> about the range concept back then :)
> 
> In any case, if you *do* want to go there, it doesn't really
> require you creating that much new stuff, especially not your own
> string/vector type.

It does if you don't want to code your stuff in a manner that there's a specific 
piece of code which owns the string, since you've now separated the string 
from the slice. Sure, it's feasible, but it's not the same thing and requires 
you to code differently than you'd do it in D. Regardless, it requires you to 
code very differently from how you'd do it in C++, so while it's quite possible 
to do something similar to slices in C++, pretty much no one does.

- Jonathan M Davis


More information about the Digitalmars-d mailing list