Skip to content
1 hidden cell
Writing Efficient Python Code
Writing Efficient Python Code
Run the hidden code cell below to import the data used in this course.
1 hidden cell
Take Notes
Add notes about the concepts you've learned and code cells with code you want to keep.
Add your notes here
# measuring time of one line code
%timeit
#can be used -r (for the number of runs), and -n (the number of loops)
%timeit -r 5 -n 10 [*range(1, 51, 2)]
# double percentage sign is used to measure multiline code like functions
%%timeit
# Add your code snippets here
%load_ext line_profiler
%lprun -f <function_name> <function_name(arg, arg1)>
# to use the memory profiler the file needs to be in the same directory
from <file_name> import <function_name>
%load_ext memory_profiler
%mprun -f <function_name> <function_name(arg, arg1)>