Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'friday,': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:module': 0.09; 'tismer': 0.09; 'windows,': 0.09; 'runs': 0.10; 'python': 0.11; '2.7': 0.14; 'random': 0.14; 'windows': 0.15; '(1,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:random': 0.16; 'time.time()': 0.16; 'unix,': 0.16; 'url:peps': 0.16; 'vmware': 0.16; 'win7': 0.16; 'language': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'programming': 0.22; 'import': 0.22; 'print': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'instead.': 0.24; 'processor': 0.24; 'subject:Code': 0.24; 'url:dev': 0.24; 'second': 0.26; 'code:': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'unix': 0.29; 'related': 0.29; 'code': 0.31; 'clock': 0.31; 'pascal': 0.31; 'url:python': 0.33; 'running': 0.33; 'subject:the': 0.34; 'subject:with': 0.35; 'but': 0.35; 'version': 0.36; 'functions.': 0.36; 'url:org': 0.36; 'seconds': 0.37; 'clear': 0.37; 'expressed': 0.37; 'christian': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'world.': 0.61; 'first': 0.61; 'times': 0.62; 'batchelder': 0.84; 'experiment': 0.84; 'faster...': 0.84; 'seconds!': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Code with random module faster on the vm than the vm host... Date: Mon, 11 Nov 2013 01:31:46 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-30-243.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384133501 news.xs4all.nl 15945 [2001:888:2000:d::a6]:33042 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59041 On 11/11/2013 01:15, Ned Batchelder wrote: > On Friday, November 8, 2013 12:48:04 PM UTC-5, Pascal Bit wrote: >> 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? > > The docs for time.clock() make clear that the meaning on Windows and Unix are different: > > "On Unix, return the current processor time as a floating point number expressed in seconds." > > "On Windows, this function returns wall-clock seconds elapsed since the first call to this function..." > > Try the experiment again with time.time() instead. > > --Ned. > http://www.python.org/dev/peps/pep-0418/ for some related reading about Python time functions. -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer Mark Lawrence