Code with random module faster on the vm than the vm host...

Pascal Bit pascalbit at hotmail.com
Fri Nov 8 12:48:04 EST 2013


Here's the code:

from random import random
from time import clock

s = clock()

for i in (1, 2, 3, 6, 8):
     M = 0
     N = 10**i

     for n in xrange(N):
         r = random()
         if 0.5 < r < 0.6:
             M += 1

     k = (N, float(M)/N)

print (clock()-s)

Running on win7 python 2.7 32 bit it uses around 30 seconds avg.
Running on xubuntu, 32 bit, on vmware on windows 7: 20 seconds!
The code runs faster on vm, than the computer itself...
The python version in this case is 1.5 times faster...
I don't understand.

What causes this?



More information about the Python-list mailing list