[Issue 5198] New: Appender much slower when appending ranges of elements than individual elements

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 10 11:24:48 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=5198

           Summary: Appender much slower when appending ranges of elements
                    than individual elements
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: schveiguy at yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy at yahoo.com> 2010-11-10 11:23:42 PST ---
Given an appender Appender!string a, the following code should be roughly
equivalent performance-wise:

a.put(' ');
a.put(" ");

But as shown by this code, the version that puts an individual character is an
order of magnitude faster.

import std.stdio;
import std.date;
import std.array;

void f0()
{
    Appender!string a;
    a.reserve(100_000_000);

    foreach(i; 0 .. 100_000_000)
    {
        a.put(' ');
    }
}

void f1()
{
    Appender!string a;
    a.reserve(100_000_000);

    foreach(i; 0 .. 100_000_000)
    {
        a.put(" ");
    }
}


void main()
{
    auto r = benchmark!(f0)(1);
    writeln(r, "ms");
    r = benchmark!(f1)(1);
    writeln(r, "ms");
}

Results:
[2433]ms
[13276]ms

Swapping the order of testing does not change the situation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list