On Sunday, August 24, 2025 6:30:08 AM Mountain Daylight Time David T. Oxygen via Digitalmars-d-learn wrote: > On Sunday, 24 August 2025 at 08:35:57 UTC, Per Nordlöw wrote: > > Which are the pros and cons of foreach vs static foreach on a > > compile time tuple in D in terms of compiler performance and > > resource usage? Does static foreach generate more ast > > duplications? > > -- > Yes, it will make the compile-time longer, but usually you can > ignore. > If you don't have `static foreach(int i;0..99999999)`,you are no > need to worry about it.
You misunderstood the question. He was asking whether the performance between foreach and static foreach differs when what's being iterated over is a compile-time construct which therefore must be iterated at compile time. And in such a sitation, the performance should be identical (or so close that you couldn't tell the difference). On the other hand, foreach(i; 0 .. 10_000) {...} and static foreach(i; 0 .. 10_000) {{...}} are completely different from one another, because the foreach would iterate at runtime, whereas the static foreach would iterate at compile time, because the arguments to foreach are not compile-time arguments. In contrast, foreach(i; AliasSeq!(1, 2, 3, 4, 5)) {...} static foreach(i; AliasSeq!(1, 2, 3, 4, 5)) {{...}} would both run at compile time, because AliasSeq is a compile-time construct and must be evaluated at compile time. - Jonathan M Davis