03.Jupyter Notebook高级-魔法命令
%run
%run C:\Users\User\Desktop\hello.py
hello world
%timeit
%timeit L = [i for i in range(1000)]
29.1 µs ± 2.98 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
%timeit L = [i for i in range(1000000)]
52 ms ± 911 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
%timeit L = [i for i in range(10)]
806 ns ± 284 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
%% timeit
%%timeit L = [] for i in range(1000): L.append(i)
236 µs ± 62.6 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
%time
%time L = [i**2 for i in range(1000)]
Wall time: 0 ns
%%time L = [] for i in range(1000): L.append(i**2)
Wall time: 13.5 ms
import random L = [random.random() for i in range(100000)] %time L.sort()
Wall time: 18.7 ms
其他魔法命令
%lsmagic