[Issue 12175] New: More efficient very common case for std.algorithm.sum
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Feb 15 02:53:32 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12175
Summary: More efficient very common case for std.algorithm.sum
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2014-02-15 02:53:30 PST ---
The most common code path of std.algorithm.sum contains:
+ Result seed = 0;
+ return reduce!"a + b"(seed, r);
I suggest to add a "static if" that tests if the input is an array (or a random
access range) and in such case instead of reduce to use a more efficient loop
like this:
immutable lenR = r.length;
for (int i = 2; i < lenR; i += 2) {
total1 += r[i];
total2 += r[i + 1];
}
return total1 + total2;
This is more efficient on most modern CPUs.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list