In [5] : a = !pwd
In [6] : a
Out[6] : ['/User/***/codespace']
5.“%time”计算代码执行时间
计算一行代码到执行时间
In [1]: str = ['foo', 'foobar', 'baz', 'qux', 'python', 'test']*100000In [2]: %time test1 = [x for x in str if x.startswith('foo')]
CPU times: user 279 ms, sys: 15.5 ms, total: 295 ms
Wall time: 287 ms
In [3]: %time test1 = [x for x in str if x[0:3] == 'foo']
CPU times: user 123 ms, sys: 4.71 ms, total: 128 ms
Wall time: 127 ms
自动多次执行并计算执行平均时间
In [9]: x = "foobar"In [10]: %timeit x.startswith("foo")
The slowest run took 4.49 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of3: 425 ns per loopIn [11]: %timeit x[0:3] == "foo"10000000 loops, best of3: 182 ns per loop