Array Appending and DRuntime

bearophile bearophileHUGS at lycos.com
Sat Apr 25 13:57:59 PDT 2009


dsimcha:
> DMD 2.019 (Last release before druntime):  42 milliseconds.
> DMD 2.020 (First release with druntime):  ~1000 milliseconds.
> DMD 2.029 (Current version):  ~1000 milliseconds.
> DMD 2.029 (Replacing ~= with the Appender struct):  18 milliseconds.
> DMD 2.029 (Replacing builtin array with rangeextra.TNew):  19 milliseconds.

I have done some more timings:

Timings, appending 100_000_000 uints, seconds:
  DMD 1.042:                 7.51
  DMD 1.042, ArrayBuilder:   1.81
  DMD 2.029:                 a lot
  DMD 2.029, Appender:      22.83

I don't like the user interface of Appender.

---------------

The code I have used:

void main() {
    uint[] foo;
    for (int i; i < 100_000_000; i++)
        foo ~= i;
}

---------------

import d.builders: ArrayBuilder;
void main() {
    ArrayBuilder!(uint) b;
    for (int i; i < 100_000_000; i++)
        b ~= i;
    uint[] arr = b.toarray;
}

---------------

import std.array: appender;
void main() {
    char[] arr;
    auto app = appender(&arr);
    for (int i; i < 100_000_000; i++)
        app.put(i);
    auto result = app.data;
}

Bye,
bearophile



More information about the Digitalmars-d mailing list