Is D slow?
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jun 9 14:11:50 PDT 2017
On 6/9/17 3:29 PM, Honey wrote:
> On Friday, 9 June 2017 at 18:32:06 UTC, Steven Schveighoffer wrote:
>> Wow, so that's how D code would look like if it were C++ :)
>
> Well, I cannot (and did not try to) hide where I am coming from. ;-)
hehe this was meant more as a dig at C++ syntax and not you, I totally
understand the reason you did it that way.
Just to show you what I meant, I changed your code to eliminate the
functors completely, the main function now looks like this:
foreach (i; 0 .. N)
{
insertionSort!((a, b) => lt(a, b))(v);
insertionSort!((a, b) => lt(b, a))(v);
}
I'm sure there's also a way to reduce the initialization of the array to
a few lines (or maybe even one?), but didn't have time to think about it.
>> I did replicate that issue on my box, and mucking around with the
>> implementation didn't help.
>>
>> In answer to the subject, no D is not slow. However, it's quite
>> possible that std.algorithm.bringToFront is slower than std::rotate,
>> or SortedRange.upperBound is slower than std::upper_bound, or both. I
>> don't think it's a design issue per se, probably more of an
>> implementation issue.
>
> Thank you for confirming the results and your factual explanation
> notwithstanding my pointed question. ;-)
>
> Maybe I was expecting too much given Andrei's performance oriented
> talks. I realize that the conceptual groundwork is more important than a
> concrete implementation that can be easily improved. However, I think
> that real world out-of-the-box performance - particularly with respect
> to toy examples (since those are small enough to be literally
> translated) - is important for prospects to gain confidence in buying
> into D.
Well, D is pretty fast, as fast as C++ or C. What I mean is that there
is no inherent overhead -- both can produce exactly the same code.
However, there are some parts of C/C++ that have been optimized to
death. It's one of those things where D's version of rotate probably
hasn't had as much scrutiny as C++'s version. We are always looking to
improve such things, and more investigation and suggestions are most
welcome! It's why I filed the bug report.
> At the current state, at least for such benchmarks, I think, I should
> not rely on standard library facilities. Unfortunately, that does not
> increase my confidence.
Try to find something besides insertion sort to test with I think ;) D
is pretty fast at a lot of things, and pleasant to write. You just found
one test case that isn't (and we will fix it, I'm sure).
-Steve
More information about the Digitalmars-d-learn
mailing list