rng is very slow when doing many small reads

Bug #1171237 reported by Bas Westerbaan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python-Crypto
New
Undecided
Unassigned

Bug Description

Crypto.Random.random.shuffle calls randrange several times. For each call, the Fortune CPRNG does some extra work, assuming the numbers will be used in different places. This makes shuffle slower than it has to be.

Only invoking the CPRNG once, by picking a number between 0 and len(x)!, makes shuffle 5 times faster.

See https://gist.github.com/bwesterb/5431057

Revision history for this message
Bas Westerbaan (bwesterb) wrote :

Correction, it's actually about 35 times faster.

Revision history for this message
Darsey Litzenberger (dlitz) wrote :

Yeah, the problem is really that random.randrange() is slow, ultimately because _UserFriendlyRNG.read() collects entropy from the operating system on every read.

summary: - random.shuffle is slow
+ rng is very slow when doing many small reads
Revision history for this message
Richard Mitchell (mitchellrj) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.