[Issue 19705] New: Static foreach slow for numeric ranges
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Feb 27 09:09:32 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19705
Issue ID: 19705
Summary: Static foreach slow for numeric ranges
Product: D
Version: D2
Hardware: x86
OS: Windows
Status: NEW
Keywords: performance
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: simen.kjaras at gmail.com
For whatever reason, static foreach is a lot slower when iterating over a
numeric range like 0..N than when iterating over a tuple. On my machine the
following examples take around 11 seconds for the 0..N cases and 5-6 seconds
when iterating over a tuple.
unittest {
enum N = 10000;
alias A = generate!N;
static foreach (i; 0..N) {} // A 11s
static foreach (i; 0..A.Length) {} // B 11s
static foreach (i; A) {} // C 5s
static foreach (i, _; A) {} // D 5s
}
template generate(int n) {
import std.meta : AliasSeq;
mixin("alias generate = AliasSeq!("~{
string result;
static foreach (i; 0..n) {
result ~= i.stringof~", ";
}
return result;
}()~");");
}
Clearly, D should be no faster than A, since it does more.
--
More information about the Digitalmars-d-bugs
mailing list