Combine Coroutines and Input Ranges for Dead-Simple D Iteration

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Tue May 1 16:37:25 PDT 2012


"jerro" <a at a.com> wrote in message 
news:qpipqzzdbpkoxtzvhefw at forum.dlang.org...
>> 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;
>

What compiler options is that with?




More information about the Digitalmars-d-announce mailing list