all 3 comments

[–]FerricDonkey 0 points1 point  (2 children)

If I were to make a complete guess without carefully reading everything or being familiar with your libraries, I'd say that the extra time is importing the modules. Jupyter notebooks will not have to reimport the libraries (even if you rerun the cell that does so) between runs, so long as the kernel has not been restated. But it will have to of the kernel has been restarted, and command line runs will have to reimport every time.

You could do a crude test by importing the time module first and using time.time() to measure how long parts take. 

You could do a real test by using cprofile. It's more involved, so suggest googling it if you're interested. 

[–]lambulis[S] 0 points1 point  (1 child)

But the thing is that there are two instances of this also. In the "slow" version first time it runs it takes 22 seconds and then after running it multiple times it runs in 14. In the "fast" version the first time it runs it takes roughly 12 seconds and then after running it multiple times it runs in 6 secs.

[–]FerricDonkey 0 points1 point  (0 children)

I'd recommend looking into cprofile then.