Trying the SnakeViz Jupyter extension for profiling

I want to try the https://jiffyclub.github.io/snakeviz/ SnakeViz Jupyter extension for profiling Python code right inside the Jupyter notebook!

Installing and loading

In [3]:
!python3 -m pip install snakeviz
python3 -m pip install snakeviz
In [4]:
%load_ext snakeviz
The snakeviz extension is already loaded. To reload it, use:
  %reload_ext snakeviz

Let's try it!

In [1]:
def carre1(i):
    return i**2

N = 10000
In [6]:
%snakeviz sum(carre1(i) for i in range(N))
 
*** Profile stats marshalled to file '/tmp/tmpj_m5ith5'. 
Embedding SnakeViz in this document...

A more serious example?

Let's try this too!

In [7]:
%%snakeviz

x = 0
for i in range(N+1):
    x += i**2

print(f"Sum i**2 for i=0 to {N} = {x}")
Sum i**2 for i=0 to 10000 = 333383335000
 
*** Profile stats marshalled to file '/tmp/tmpzkimd5wr'. 
Embedding SnakeViz in this document...

My feeling about this extension

I think it's quite useful, and well designed.

It's completely "over kill" for any teaching at bac-2/bac+3 level (in France), but I keep it in mind, in case I need to use it for my own work.

Conclusion

That was nice!

Have a look at my other notebooks.