Here's my script.py
:
@profile
def primes(n):
if n == 2:
return [2]
elif n < 2:
return []
s = range(3, n + 1, 2)
mroot = n ** 0.5
half = (n + 1) / 2 - 1
i = 0
m = 3
while m <= mroot:
if s[i]:
j = (m ** 2 - 3) / 2
s[j] = 0
while j < half:
s[j] = 0
j += m
i += 1
m = 2*i + 3
return [2] + [x for x in s if x]
number = 40000
elts = primes(number)
I installed line_profiler
:
$ pip install line_profiler
and ran it as follows
$ kernprof -l -v script.py
Wrote profile results to profiling.py.lprof
Timer unit: 1e-06 s
which is strange...no timing results by line!
So I looked into the dump, but no luck there either:
$ python -m line_profiler profiling.py.lprof
Timer unit: 1e-06 s
Any ideas how I'm using this library wrong?