D vs C++ - Where are the benchmarks?
Brad Anderson
eco at gnuk.net
Mon Jul 1 09:50:55 PDT 2013
On Monday, 1 July 2013 at 06:28:57 UTC, 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.
Boost recently added string_ref, "a non-owning reference to a
string":
http://www.boost.org/doc/libs/1_53_0/libs/utility/doc/html/string_ref.html
Gets you something similar to slices but is inherently more
dangerous to use than GC backed slices.
More information about the Digitalmars-d
mailing list