[triangle-zpug] why is this using a lot of memory?
Chris Calloway
cbc at unc.edu
Tue Mar 25 19:39:29 CET 2008
On 3/25/2008 11:59 AM, Joseph Mack NA3T wrote:
> thanks both of you. Will go lookup xrange()
In addition to the memory-conserving xrange, you don't need the loop.
This will do the same thing:
>>> sum(xrange(10000000))
49999995000000L
>>>
I thought this was slow. So I tried doing this with scipy.weave.inline.
See:
http://incm.cnrs-mrs.fr/LaurentPerrinet/ScientificPython#head-4f78ccfcc91b87436966e15a294263dbcd400a7e
for a pretty similar example.
But ironically it was much slower, as the C++ took so long to compile on
the fly. Plus, you need memory, as you need to pass a populated numpy
array to the C++ instead of a Python iterator. Python wins!
I had no problem with the original example, I guess because I have
enough memory.
Man, some days I waste a lot of time on brain teasers.
--
Sincerely,
Chris Calloway
http://www.secoora.org
office: 332 Chapman Hall phone: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599
More information about the TriZPUG
mailing list