D vs C++ - Where are the benchmarks?
monarch_dodra
monarchdodra at gmail.com
Sun Jun 30 23:28:54 PDT 2013
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.
More information about the Digitalmars-d
mailing list