Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #92280
| Date | 2015-06-07 10:59 -0700 |
|---|---|
| From | "C.D. Reimer" <chris@cdreimer.com> |
| Subject | Re: Python Random vs. Cython C Rand for Dice Rolls |
| References | <55747C96.7090006@cdreimer.com> <CAPTjJmqq7LZPusE12mjrvywAZ3n=zo3Af28wtUkEVTz3Pga_7Q@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.267.1433700003.13271.python-list@python.org> (permalink) |
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
Re: Python Random vs. Cython C Rand for Dice Rolls "C.D. Reimer" <chris@cdreimer.com> - 2015-06-07 10:59 -0700
csiph-web