python -m timeit [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...]
The -s flags an argument that should be executed only once. Multiple -s [setup code] lines can be included. There can also be multiple statements which is, or are, executed many times and the timing reported. I was curious about the relative speed of two approaches to grouping list elements (post here). I put the code for the two functions into a module
test.py
(the listing is at the end of the post).Here is what I got:
The itertools solution takes 2-3 times as long, and getting the actual list rather than a generator or iterator has overhead as well.