Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92280

Re: Python Random vs. Cython C Rand for Dice Rolls

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <chris@cdreimer.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.018
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'subject:Python': 0.05; 'indexing': 0.07; 'array.': 0.09; 'script,': 0.09; 'python': 0.11; 'statements,': 0.16; 'subject:Cython': 0.16; 'threw': 0.16; 'time.time()': 0.16; 'wrote:': 0.16; 'element': 0.18; 'together.': 0.22; 'from:addr:chris': 0.22; 'pass': 0.22; 'am,': 0.23; '(like': 0.23; 'import': 0.24; 'seems': 0.24; 'header:In-Reply-To:1': 0.24; 'script': 0.25; 'header:User-Agent:1': 0.26; 'chris': 0.26; 'error': 0.27; "i'm": 0.29; 'looks': 0.29; 'container': 0.29; 'received:dreamhost.com': 0.29; 'received:g.dreamhost.com': 0.29; 'way?': 0.29; 'correct': 0.29; 'print': 0.31; 'fixed': 0.31; 'received:10.0.0': 0.32; 'point': 0.33; 'problem': 0.33; 'particular,': 0.33; 'right?': 0.33; 'received:10.0': 0.34; 'wrong': 0.35; 'to:addr:python-list': 0.35; 'list': 0.35; 'but': 0.36; 'possible': 0.36; 'received:10': 0.37; 'subject:: ': 0.37; 'list.': 0.37; 'skip:4 10': 0.38; 'end': 0.39; 'means': 0.39; 'to:addr:python.org': 0.39; 'takes': 0.39; 'your': 0.60; 'side': 0.62; 'please,': 0.63; 'charset:windows-1252': 0.65; 'subject:. ': 0.66; 'further,': 0.72; 'random,': 0.84; 'run?': 0.84; 'try,': 0.84
DKIM-Signature v=1; a=rsa-sha1; c=relaxed; d=cdreimer.com; h=message-id :date:from:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; s=cdreimer.com; bh=X96R fgD109mkv9Qqt9eYBNzmNl0=; b=Wwd+UDAPZU6QFh3hkVEwmosIrphj/+JRb0Bg a3y6SIaM/unVX6GgupV+bJptFfOv9e7NFstdN3YGo3Vf+w9gE6IdQTZcmZu5X0jG g6xVYLw75BYLNar3jJxfN9XwkceIcUS0SnDWwJeDxtPgITjWZPDhD7mKiT+owUkR Lxk0+FA=
Date Sun, 07 Jun 2015 10:59:53 -0700
From "C.D. Reimer" <chris@cdreimer.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Python Random vs. Cython C Rand for Dice Rolls
References <55747C96.7090006@cdreimer.com> <CAPTjJmqq7LZPusE12mjrvywAZ3n=zo3Af28wtUkEVTz3Pga_7Q@mail.gmail.com>
In-Reply-To <CAPTjJmqq7LZPusE12mjrvywAZ3n=zo3Af28wtUkEVTz3Pga_7Q@mail.gmail.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.267.1433700003.13271.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433700003 news.xs4all.nl 2944 [2001:888:2000:d::a6]:52461
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92280

Show key headers only | View raw


On 6/7/2015 10:23 AM, Chris Angelico wrote:
> Before you go any further, can you just try this script, please, and
> see how long it takes to run?
>
> import random, time
> startTime = time.time()
> for i in range(50000000):
>      pass
> print '\n', time.time() - startTime
>
> I know, seems a stupid thing to try, right? But you're using Python 2,
> as evidenced by the print statements, and that means that range() is
> constructing a 50M element list. It's entirely possible that that's a
> significant part of your time - allocating all that memory, populating
> it, and then disposing of it at the end (maybe).

PS Z:\projects\programming\python\basic_games\fastdice> python test_random_time.py

4.84700012207


So... I'm not looking at the problem on the Python side in the correct way?

In particular, I'm using the wrong container type?

I was thinking "array" (like the Cython version) when I put the Python 
script together. I got an error message at one point about indexing the 
"list" that threw me off for a while. Since it looks like an array, 
walks like an array, and quack likes array, I fixed the indexing problem 
like an array. A list != array? :)

Chris R.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python Random vs. Cython C Rand for Dice Rolls "C.D. Reimer" <chris@cdreimer.com> - 2015-06-07 10:59 -0700

csiph-web