[Python-ideas] Python's Source of Randomness and the random.py module Redux
Donald Stufft
donald at stufft.io
Thu Sep 10 19:02:12 CEST 2015
On September 10, 2015 at 10:21:11 AM, Donald Stufft (donald at stufft.io) wrote:
> > Assuming Theo's claim of the speed of the ChaCha based arc4random
> function
> is accurate, which I haven't tested but I assume he's smart enough
> to know
> what he's talking about WRT to speed of it.
I wanted to try and test this. These are not super scientific since I just ran
them on a single computer once (but 10 million iterations each) but I think it
can probably give us an indication of the differences?
I put the code up at https://github.com/dstufft/randtest but it's a pretty
simple module. I'm not sure if (double)arc4random() / UINT_MAX is a reasonable
way to get a double out of arc4random (which returns a uint) that is between
0.0 and 1.0, but I assume it's fine at least for this test.
Here's the results from running the test on my personal computer which is
running the OSX El Capitan public Beta:
$ python test.py
Number of Calls: 10000000
+---------------+--------------------+
| method | usecs per call |
+---------------+--------------------+
| deterministic | 0.0586802460020408 |
| system | 1.6681434757076203 |
| userland | 0.1534261149005033 |
+---------------+--------------------+
I'll try it against OpenBSD later to see if their implementation of arc4random
is faster than OSX.
-----------------
Donald Stufft
PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA
More information about the Python-ideas
mailing list