2 ms·
True. But you should also put the setup in a -s option, because you're not timing the imports. And you don't really need the loop, because timeit does a bunch o
by benhoyt 14y ago
True. But you should also put the setup in a -s option, because you're not timing the imports. And you don't really need the loop, because timeit does a bunch of loops for you:
>python -m timeit -s "from operator import itemgetter; elem0 = itemgetter(0)" "elem0('s')"
10000000 loops, best of 3: 0.095 usec per loop
>python -m timeit -s "from operator import itemgetter; elem0 = lambda x: x[0]" "elem0('s')"
10000000 loops, best of 3: 0.138 usec per loop