On Tue, 21 Oct 2008 at 07:50AM -0700, pong wrote: > I wrote two list tests: > > def test1(): > for k in range(10^3): > v=[2*random() for j in range(10)] > else: pass > > def test2(): > for k in range(10^3): > v=list(2*vector([random() for j in range(10)])) > else: pass > > It turns out that > time test1() gives around 8s CUP time while time test2() shows only > 0.35s CUP time is used. Wow!
Also, instead of doing your own loops, you can use %timeit: sage: %timeit [2*random() for j in range(10)] 100000 loops, best of 3: 6.87 µs per loop sage: %timeit list(2*vector([random() for j in range(10)])) 10000 loops, best of 3: 112 µs per loop Using list comprehensions is almost always a good choice in Sage/Python; as I understand (and as we see above), they're very well-optimized. Dan -- --- Dan Drake <[EMAIL PROTECTED]> ----- KAIST Department of Mathematical Sciences ------- http://mathsci.kaist.ac.kr/~drake
signature.asc
Description: Digital signature