Too complicated code for generating a random string?

Iain Buclaw ibuclaw at ubuntu.com
Sun Feb 24 01:44:01 PST 2013


On 23 Feb 2013 20:25, "jerro" <a at 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';
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130224/06fd57f2/attachment.html>


More information about the Digitalmars-d mailing list