April 2016
Intermediate to advanced
486 pages
9h 21m
English
Before we can start improving performance, we need a reliable method to measure it. Python has a really nice module (timeit) with the specific purpose of measuring execution times of bits of code. It executes a bit of code many times to make sure there is as little variation as possible and to make the measurement fairly clean. It's very useful if you want to compare a few code snippets. Following are example executions:
# python3 -m timeit 'x=[]; [x.insert(0, i) for i in range(10000)]' 10 loops, best of 3: 30.2 msec per loop # python3 -m timeit 'x=[]; [x.append(i) for i in range(10000)]' 1000 loops, best of 3: 1.01 msec per loop # python3 -m timeit 'x=[i for i in range(10000)]' 1000 loops, best of 3: ...
Read now
Unlock full access