Too complicated code for generating a random string?
jerro
a at a.com
Sat Feb 23 12:21:17 PST 2013
> 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.
By the way, this is not a very good benchmark for ranges because
most of the time is spent generating random numbers.
More information about the Digitalmars-d
mailing list