3

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?

lollercoaster
  • 15,969
  • 35
  • 115
  • 173
  • 1
    I have had trouble too. A work-around pending a better answer: if you have `kernprof.py` and `line_profiler.py` in the same directory as the script you're testing you can run `python kernprof.py -l -v my_script.py > some_output_text_file_to_direct_output`. That should at least show some kind of output to confirm the script you're testing is not at fault (seems ok though). – roganjosh Apr 08 '17 at 10:48

0 Answers0