Bartosz Milewski seems to like D more than C++ now :)

Piotr Szturmaj bncrbme at jadamspam.pl
Fri Sep 20 10:59:32 PDT 2013


On 20.09.2013 19:45, Andrei Alexandrescu wrote:
> On 9/20/13 9:51 AM, Piotr Szturmaj wrote:
>> On 20.09.2013 17:28, Andrei Alexandrescu wrote:
>>> On 9/20/13 2:36 AM, bearophile wrote:
>>>> In D it's often better to use std.algorithm/range instead of raw
>>>> foreach
>>>> loops (despite probably unlike C++ in D a heavy use of ranges leads
>>>> to a
>>>> lower performance, even if you use the LDC2 compiler).
>>>
>>> Why would there be a performance loss?
>>
>> Because range concept underutilize current CPUs. I don't know if all
>> empty/front/popFront are inlined. I suppose some templated functions
>> are, but surely not all of them.  What will be faster, calling all of
>> those functions for each element or traversing memory using a loop?
>
> This is just a supposition. Inlining is automatic and just works subject
> to the constraints chosen by the implementers. It's not like there's a
> guy sitting there and getting bored of inlining.

This was not my point. I know that inlining is automatic, but certainly 
not all functions are automatically inlined and all of those non-inlined 
carry some overhead.

>> Of course 2nd option will be faster, because the act of traversing
>> (cached) memory does not have the overhead of a function call.
>
> No, no.
>
>> Some time ago I proposed a hybrid range concept where the front() is an
>> array. All algorithms would first traverse the memory in this array,
>> then call popFront to get another array (slice). In this way, function
>> call overhead is minimized because it's paid sparsely rather than for
>> each range element.
>
> That's a good idea but for completely different reasons.

Could you elaborate? :)


More information about the Digitalmars-d mailing list