When using from IPython, total time reported at the end accumulates. #13

elpres opened this Issue Sep 3, 2012 · 2 comments


None yet

2 participants

elpres commented Sep 3, 2012

If I profile a script such as this one:

def main():
    # do something

if __name__ == '__main__':
    import statprof

and call it from IPython by repeatedly executing run script.py, the total time grows each time by duration of the execution (e.g. 1s, 2s, 3s, ...).

Without looking very deeply into the code, the function clock() gets its time from os.times(). I am not certain what the values in the list returned by it represent, but the result of clock() seems to be the same as what time.clock(), which is the CPU time since the module has been imported and that matches well with the observed behavior. Maybe it would be better to use time.time() (which returns an absolute time value), then save the current time at statprof.start(), and calc the difference by time.time() - starttime?

Also, I've noticed this today, but I've been doing the same thing a couple of days ago and was getting more or less constant values for each run. But I can't remember whether I've been working from inside IPython or calling the script directly from the shell. So I'm not sure it really is well reproducible.

durin42 commented Oct 9, 2015

Is this still an issue?

elpres commented Oct 14, 2015

Yes, it is. Here's a test:

  1. Save this code as test.py:

    import statprof
    def fib(n):
        if n < 2:
            return 1
            return fib(n - 1) + fib(n - 2)
    with statprof.profile():
  2. From ipython, call run test.py several times.

@elpres elpres referenced this issue Oct 14, 2015

Fix for #13 #23

@elpres elpres closed this Oct 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment