Combine Coroutines and Input Ranges for Dead-Simple D Iteration

jerro a at a.com
Tue May 1 14:56:23 PDT 2012


On Tuesday, 1 May 2012 at 20:49:48 UTC, Nick Sabalausky wrote:
> "jerro" <a at a.com> wrote in message
> news:sxfngaqnhwxqookrvkif at forum.dlang.org...
>> On Tuesday, 1 May 2012 at 08:26:45 UTC, Nick Sabalausky wrote:
>>> A little write-up I just did on something I thought was 
>>> pretty cool:
>>>
>>> Combine Coroutines and Input Ranges for Dead-Simple D 
>>> Iteration
>>> https://www.semitwist.com/articles/article/view/combine-coroutines-and-input-ranges-for-dead-simple-d-iteration
>>
>> This is fun and all, but because of the horrible performance 
>> we really shouldn't be recommending people to use it.
>
> So it is bad performance?

It has bad performance compared to something like iota - I get
about 15 million iterations per second for this loop:

struct Iterable
{
      alias string visitType;

      void visit()
      {
          foreach(i; 0 .. 10_000_000)
              yield(i);
      }
}

...

foreach(el; visitor(i))
       sum ++;

  using Robert Clipsham's code, compared to billions iterations
per second with a regular loop. The problem is that people new
to D could see this, assume it performs similar to ranges like
iot and then wonder why their code is slow.


More information about the Digitalmars-d-announce mailing list