Newsgroups, off-topic

Joseph Wakeling joseph.wakeling at webdrake.net
Fri Apr 23 10:43:41 PDT 2010


Steven Schveighoffer wrote:
>> I do see the point about allocation and reallocation -- what was
>> bothering me a bit was that even taking those aspects out of the code
>> and preallocating everything, I could write C++ code that _didn't_
>> preallocate and still ran (much) faster ... :-)
> 
> If you are comparing vector's push_back to D's array append after
> pre-allocating, you are still not comparing apples to apples...

No ... !  That was true in the original code I posted, but following
bearophile's kind example that part of the code was updated to a form
along the lines of,

    x.length = 5_000_000;

    for(uint i=0;i<100;++i) {
        size_t pos = 0;
        for(uint j=0;j<5_000;++j) {
            for(uint k=0;k<1_000;++k) {
                x[pos++] = j*k;
            }
        }
    }

... which in itself indeed runs about the same speed as C++.  But that's
not the main cause of the difference in running time of the codes.

> D's standard library should have a construct that duplicates the
> performance of vector, I'm not sure if there is anything right now.  I
> thought Appender would do it, but you have said in the past it is slow. 
> This needs to be remedied.

It would be great -- but by itself it's not responsible for the timing
differences I'm observing.

Best wishes,

    -- Joe


More information about the Digitalmars-d-learn mailing list