[Tutor] Why is random.choice so much slower than random.random()?

Dick Moores rdm at rcblue.com
Thu Oct 12 14:56:55 CEST 2006


At 04:33 AM 10/12/2006, Kent Johnson wrote:
>Looking at the code and your numbers, my guess is that the time to make
>a Python function call on your computer is about 2 microseconds (20 msec
>/ 10000). (I mean the entire overhead - looking up the function and
>actually calling it.)

Hm. Does this test include the entire overhead?

C:\>python -m timeit  -r 3 -s"from random import random" "random()"
10000000 loops, best of 3: 0.157 usec per loop

Dick





More information about the Tutor mailing list