Code Profiling Flashcards
What’s the result of %timeit?
(mean +- stdandard deviation of 7 runes, 1000loops).
When not defined, %timeit will configure by its own how many loops to make (depending on how fast the profiled operation is)
How to configure %timeit to make 5 runs and 100 loops per run?
%timeit -r5 -n100 <code></code>
What’s the difference between %time and %timeit
%time makes only one repetition while %timeit many.
Why is %time > %timeit when the same code is profiled, even though %timeit did run it multiple times?
%timeit makes some configurations under the hood that prevent some events like garbage collection to affect the timing.
%time doesn’t do this so the calculated time contains the time of garbage collection etc. and the result is much bigger than %timeit
When should u use %%time instead of %time?
When you want to profile multiline scripts
Explain the results of %time:
CPU time: user 404ms, sys .196ms
Wall time: 407ms
CPU time is the time that the CPU spent on executing the program. It is divided in user time and sys time which is the time that the cpu was in user-mode and the time cpu was in kernel-mode )time spent in system calls).
Wall time is the total time. The time that passed from the moment that the program started until the execution was terminated.
Whats the use of %prune
Profile a function like sum_of_lists(1000)
Whats the output of a %prune?
A table showing per statement ncalls, totaltime, percall, cumtime, percall where ncalls is number of calls, tottime is time for all calls, percall is tottime/ncalls, cumtime is the time spent in subfunctions
Whats the use of %lprune
Line by line profiling a function
Output of lprune?
line, hits, time, perhit, %time
Is %memit like %timeit for memory?
Yes
Is %mprun like %lprun for memory?
Yes