Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Why sigma(n) seems not so performant?

When one asks sage: sigma? it gies at the end: " *Craig Citro (2007-06-01): rewrote for huge speedup" Now : sage: %timeit sage: for n in xsrange(1,10000): c=sigma(n) 5 loops, best of 3: 181 ms per loop

but it seems much quicker when you directly sum the divisors

sage: %timeit sage: def s(n): return sum(divisors(n)) sage: for n in xsrange(1,10000): c=s(n) 5 loops, best of 3: 44.8 ms per loop

The same with sigma(n,k). Why that happens?

Why sigma(n) seems not so performant?

When one asks sage: sigma? it gies gives at the end: " *Craig Citro (2007-06-01): rewrote for huge speedup" Now : I try to time it:

sage: %timeit sage: for n in xsrange(1,10000): c=sigma(n) 5 loops, best of 3: 181 ms per loop

but it seems much quicker when you directly sum the divisors

sage: %timeit sage: def s(n): return sum(divisors(n)) sage: for n in xsrange(1,10000): c=s(n) 5 loops, best of 3: 44.8 ms per loop

The same with sigma(n,k). Why that happens?

Why sigma(n) seems not so performant?

When one asks sage: sigma? sigma?

it gives at the end:
" *Craig Citro (2007-06-01): rewrote for huge speedup" speedup"

Now I try to time it:

sage: %timeit %timeit

sage: for n in xsrange(1,10000): c=sigma(n) c=sigma(n)

5 loops, best of 3: 181 ms per loop

but it seems much quicker when you directly sum the divisors

sage: %timeit %timeit

sage: def s(n): return sum(divisors(n)) sum(divisors(n))

sage: for n in xsrange(1,10000): c=s(n) c=s(n)

5 loops, best of 3: 44.8 ms per loop

The same with sigma(n,k). Why that happens?

Why sigma(n) seems not so performant?

When one asks sage: sigma?

it gives at the end:
" *Craig Citro (2007-06-01): rewrote for huge speedup"

Now I try to time it:

sage: %timeit

sage: for n in xsrange(1,10000): c=sigma(n)

5 loops, best of 3: 181 ms per loop

but it seems much quicker when you directly sum the divisors

sage: %timeit

sage: def s(n): return sum(divisors(n))

sage: for n in xsrange(1,10000): c=s(n)

5 loops, best of 3: 44.8 ms per loop

The same with sigma(n,k). Why that happens?

Why sigma(n) seems not so performant?performant for small n?

When one asks sage: sigma?

it gives at the end:
" *Craig Citro (2007-06-01): rewrote for huge speedup"

Now I try to time it:timeit sigma(n):

sage: %timeit

sage: for n in xsrange(1,10000): c=sigma(n)

5 loops, best of 3: 181 ms per loop

but it seems much quicker when you directly sum the divisors

sage: %timeit

sage: def s(n): return sum(divisors(n))

sage: for n in xsrange(1,10000): c=s(n)

5 loops, best of 3: 44.8 ms per loop

The same with sigma(n,k). Why that happens?happens (for relatively small n)?

Why sigma(n) seems not so performant for small n?

When I try to timeit sigma(n):

sage: %timeit

sage: for n in xsrange(1,10000): c=sigma(n)

5 loops, best of 3: 181 ms per loop

but it seems much quicker when you directly sum the divisors

sage: %timeit

sage: def s(n): return sum(divisors(n))

sage: for n in xsrange(1,10000): c=s(n)

5 loops, best of 3: 44.8 ms per loop

The same with sigma(n,k). Why that happens (for relatively small n)?

Why sigma(n) seems not so performant for small n?

When I try to timeit sigma(n):

sage: %timeit

sage: for n in xsrange(1,10000): c=sigma(n)

5 loops, best of 3: 181 ms per loop

but it seems much quicker when you directly sum the divisors

sage: %timeit

sage: def s(n): return sum(divisors(n))

sage: for n in xsrange(1,10000): c=s(n)

5 loops, best of 3: 44.8 ms per loop

The same with sigma(n,k). Why that happens (for relatively small n)?