Skip to content

Instantly share code, notes, and snippets.

@m4nh
Created May 20, 2020 11:10
Show Gist options
  • Save m4nh/e47794f5165e1c3b346a920af3fe8a1f to your computer and use it in GitHub Desktop.
Save m4nh/e47794f5165e1c3b346a920af3fe8a1f to your computer and use it in GitHub Desktop.
#python #profiling

Timing test:

%timeit -n 1 -r 1 test_function()

where n is the number of consecutive tests and r is the repetition for each test

Simple Profile

%prun load_data()

Profile generic function with functions hit counter ordered by occurences

Line Profiler

Install:

pip install line_profiler

Load profiler in IPython

%load_ext line_profiler

Call profiler:

%lprun -f <FUNCTION_TO_CHECK> <FUNCTION_TO_RUN>

FUNCTION_TO_CHECK is the reference (not the quoted string) to the function to check line-by-line and FUNCTION_TO_RUN is the piece-of-code or function to profile (the latter should call the former...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment