On 23 Feb 2013 20:25, "jerro" <a@a.com> wrote:
>>
>> BTW, I think the clearest remains my generator proposal:
>> string randomString =
>> fastGenerator!(() => letters[uniform(0, $)]).take(9).array;
>
>
> If the goal was to replace iota(n).map, it may be better to just have something like:
>
> generate!(() => letters[uniform(0, $)])(n).array
>
> But of course, your fastGenerator is more general. I personally don't often have a need to generate an infinite range in this way, but other people may.
>
>
>> Any chance you could tell me how it fares in your bench?
>
>
> I used this code:
>
> auto tmp = FastGenerator!(() => letters[uniform(0, $)])().take(n).array;
>
> When I build it with GDC, it performs about the same as the code that uses iota and map. When I build it with DMD it's about 10% slower than the code that uses iota and map. It seems that DMD fails to inline the lambda in this case.
>
That is deliberate on gdc's part to mark all lambdas as inlineable as most just do one computation and don't require any custom static chain built to access locals in parent functions. :)
Regards
----
Iain Buclaw
*(p < e ? p++ : p) = (c & 0x0f) + '0';