digitalmars.D.bugs - [Issue 5198] New: Appender much slower when appending ranges of elements than individual elements
- d-bugmail puremagic.com (55/55) Nov 10 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5198
- d-bugmail puremagic.com (14/14) Nov 10 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5198
- d-bugmail puremagic.com (16/16) Dec 27 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5198
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 puremagic.com ReportedBy: schveiguy yahoo.com 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: -------
Nov 10 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5198 Andrei Alexandrescu <andrei metalanguage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED CC| |andrei metalanguage.com 11:55:35 PST --- Great catch! I'm marking this as "assigned" as I see you've already assign it to yourself. Long term I wonder whether we should include performance tests as part of build acceptance tests. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 10 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5198 Steven Schveighoffer <schveiguy yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED Resolution| |FIXED 11:20:47 PST --- turns out the appender was not reserving any extra space when appending an array, it was simply reallocating -- just enough to hold the existing data + the new data (in this example, 1 more element). I fixed it so the same algorithm used to expand the array for one element is now used to append an array of elements. changeset http://www.dsource.org/projects/phobos/changeset/2237 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 27 2010