Combine Coroutines and Input Ranges for Dead-Simple D Iteration
jerro
a at a.com
Tue May 1 15:15:19 PDT 2012
> Compared to normal iteration schemes, yes. It may be
> comparable to opApply in terms of performance though. If
> you're curious, look at the Fiber context switching code
> (starting at switchIn and switchOut).
It's much slower than opApply. This loop takes 70s on my machine:
foreach(el; visitor(Iterable(1000_000_000)))
sum += 1;
And this one takes 2.7s:
auto iter(int n)
{
struct I
{
int n;
int opApply(int delegate(ref int) dg)
{
for(int i = 0; i < n; i++)
if(int r = dg(i))
return r;
return 0;
}
}
return I(n);
}
foreach(el; iter(1000_000_000))
sum += 1;
More information about the Digitalmars-d-announce
mailing list