Q:

Change Time Unit with Kernprof

I've started looking for bottlenecks in Python using line_profiler. Right now, I am doing that by running
kernprof -l -v myFile.py

However, the unit of time seems to be at 1e-6, which lead to output results such as 132329040. How can I increase the time interval to make the output more readable for larger time deltas?

A:

That is a feature so far only present via Jupyter line magic, as discussed here. It can be accessed via the "-u" flag, followed by the timer unit, in seconds. This is a sample usage:
def m():
  return [0]*10**8

%lprun -u 1e-3 -f m m()

Which displays the output with timer unit in milliseconds:
Out:
Timer unit: 0.001 s

Total time: 0.363548 s
File: 
Function: m at line 1

Line # Hits Time Per Hit % Time Line Contents
==============================================================
1 def m():
2 1 363.5 363.5 100.0 return [0]*10**8

As documented in this PR.

