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


Groups > comp.lang.python > #92280 > unrolled thread

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

Started by"C.D. Reimer" <chris@cdreimer.com>
First post2015-06-07 10:59 -0700
Last post2015-06-07 10:59 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

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

From"C.D. Reimer" <chris@cdreimer.com>
Date2015-06-07 10:59 -0700
SubjectRe: Python Random vs. Cython C Rand for Dice Rolls
Message-ID<mailman.267.1433700003.13271.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web