Benchmarking
It's easy to take benchmarks too seriously – graphics card enthusiasts have been doing so for years. In our tutorial we use the cProfile module which enables you to count and time each function call. This can provide valuable data about where the bottlenecks in your code are, which might not be immediately obvious.
CProfile is designed to be as lightweight and unobtrusive as possible, but if you have a tiny function that’s called millions of times, then that's millions of tallying calls and they all add up. If the function is really small, this means that more time is spent benchmarking than is spent doing whatever it is the function does, and so the result is largely meaningless. If you're confident a small function can't be sped up any more, it's best to disable the profiler. If you're not so confident, then by all means continue to benchmark such small functions, but rest assured that they will work a lot faster without the profiler interfering.
If you just want to measure 'wall time', which is the total time it takes for your code fragment to run, then the module may be more appropriate. For example to test (from the interpreter) a function called from a module three times:
The default for is a million, which is why it’s a good idea to specify your own value here. You will need to specify your module in the parameter even if you have previously imported it, since will not inherit this namespace.