Code Profiling Flashcards

1
Q

What’s the result of %timeit?

A

(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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to configure %timeit to make 5 runs and 100 loops per run?

A

%timeit -r5 -n100 <code></code>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s the difference between %time and %timeit

A

%time makes only one repetition while %timeit many.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why is %time > %timeit when the same code is profiled, even though %timeit did run it multiple times?

A

%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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When should u use %%time instead of %time?

A

When you want to profile multiline scripts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain the results of %time:
CPU time: user 404ms, sys .196ms
Wall time: 407ms

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Whats the use of %prune

A

Profile a function like sum_of_lists(1000)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Whats the output of a %prune?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Whats the use of %lprune

A

Line by line profiling a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Output of lprune?

A

line, hits, time, perhit, %time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Is %memit like %timeit for memory?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Is %mprun like %lprun for memory?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly