[erlang-questions] Fastest pseudo-random number-generator: erlang:statistics(io) ?
Dave Smith
dizzyd@REDACTED
Tue Nov 24 16:20:32 CET 2009
On Tue, Nov 24, 2009 at 8:00 AM, Thijs <thijsterlouw@REDACTED> wrote:
> benchmark results :
>
> erlang:now() 288.090
> erlang:statistics(io) 2.730.853
> erlang:statistics(wall_clock) 280.396
> erlang:statistics(runtime) 510.765
> erlang:statistics(reductions) 471.688
> erlang:statistics(context_switches) 493.851
> random:uniform() 870.261
Off the top of my head, I have to wonder if using statistics(io) is
going to yield sufficient pseudo-randomness for load distribution
purposes. If you consider that most IO is likely to be a block size
modulo 8 (for efficiency) it seems like you might get a skewed
distribution. A simpler (and perhaps faster) approach would be to just
maintain a counter that gets atomically incremented on each call -- a
port driver or ETS table would suffice and have similar amounts of
contention as the call to statistics.
My $0.02...and you know how weak the dollar has been these days. :)
D.
More information about the erlang-questions
mailing list