:\codepypy - timeit - - - "[ * for in range( )] loopsbest of usec per loop :\codepy - - timeit - - - "[abs(xfor in range( )] loopsbest of usec per loop :\codepy - - timeit - - - "[abs(xfor in range( )] loopsbest of usec per loop :\codepypy - timeit - - - "[abs(xfor in range( )] loopsbest of usec per loop these results are essentially the same as those for earlier tests in this on the same types of code when applying * cpython and pypy are again and faster than cpython respectivelyshowing that timer choice isn' factor for the abs(xwe timed under the homegrown timer earlier (timeseqs py)these two pythons are faster than by small constant and just as beforeimplying that timeit' different code structure doesn' impact relative comparisons--the type of code being tested fully determines the size of speed differences subtle pointnotice that the results of the last three of these testswhich mimic tests run for the homegrown timer earlierare basically the same as beforebut seem to incur small net overhead for range usage differences--it was prebuilt list formerlybut here is either generator or list built anew on each inner total loop in other wordswe're not timing the exact same thingbut the relative speeds of the pythons tested are the same timing multiline statements to time larger multiline sections of code in api call modeuse line breaks and tabs or spaces to satisfy python' syntaxcode read from source file already will because you pass python string objects to python function in this modethere are no shell considerationsthough be careful to escape nested quotes if needed the followingfor instancetimes loop alternatives in python you can use the same pattern to time the file-line-reader alternatives in :\codepy - import timeit min(timeit repeat(number= repeat= stmt=" [ ]\nfor in range(len( )) [ + ") min(timeit repeat(number= repeat= stmt=" [ ]\ni= \nwhile len( ):\ \tl[ + \ \ti + ") min(timeit repeat(number= repeat= stmt=" [ ]\nm [ for in ]") to run multiline statements like these in command-line modeappease your shell by passing each statement line as separate argumentwith whitespace for indentation-timing iterations and pythons with timeit