later reindents for its own statement nesting purposes leading spaces may work better for indentation than tabs in this modeand be sure to quote the code arguments if required by your shellc:\codepy - - timeit - - " [ , , , , ]" = "while len( ): [ + + loopsbest of usec per loop :\codepy - - timeit - - " [ , , , , ]" [ for in ] loopsbest of usec per loop other usage modessetuptotalsand objects the timeit module also allows you to provide setup code that is run in the main statement' scopebut whose time is not charged to the main statement' total--potentially useful for initialization code you wish to exclude from total timesuch as imports of required modulestest function definitionand test data creation because they're run in the same scopeany names created by setup code are available to the main test statementnames defined in the interactive shell generally are not to specify setup codeuse - in command-line mode (or many of these for multiline setupsand setup argument string in api call mode this can focus tests more sharplyas in the followingwhich splits list initialization off to setup statement to time just iteration as rule of thumbthoughthe more code you include in test statementthe more applicable its results will generally be to realistic codec:\codepython - timeit - - " [ , , , , ]" [ for in ] loopsbest of usec per loop :\codepython - timeit - - - " [ , , , , ]" [ for in ] loopsbest of usec per loop here' setup example in api call modei used the following type of code to time the sort-based option in ' minimum value example--ordered ranges sort much faster than random numbersand are faster sorted than scanned linearly in the example' code under (adjacent strings are concatenated here)from timeit import repeat min(repeat(number= repeat= setup='from mins import min min min \ 'vals=list(range( ))'stmt'min (*vals)') min(repeat(number= repeat= setup='from mins import min min min \ 'import random\nvals=[random random(for in range( )]'stmt'min (*vals)') the benchmarking interlude