On Thursday, August 22, 2013 6:21:13 AM UTC-7, John Cremona wrote:
>
> Then use srange() which yields Integers.
>
> John
>
The appropriate answer should be: use xsrange, unless you explicitly need
the integers as a list. The extra memory footprint of srange will probably
be detrimental to performance.
except that it isn't uniformly the case:
sage: timeit("for i in xsrange(1000000): a=i")
5 loops, best of 3: 157 ms per loop
sage: timeit("for i in srange(1000000): a=i")
5 loops, best of 3: 179 ms per loop
sage: timeit("for i in xsrange(1000): a=i")
625 loops, best of 3: 226 µs per loop
sage: timeit("for i in srange(1000): a=i")
625 loops, best of 3: 219 µs per loop
so perhaps with a little more careful programming (cythonizing xsrange?)
one might be able to get the appropriate advice to be the uniformly correct
advice as well.
I haven't timed it, but there's a good chance that writing the looping in
cython to use a straight C-int and converting that (once) to an Integer, or
using the while loop, is faster than deal with the overhead from (x)srange,
even if they were optimized.
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.