command line (this is just what pybench does internally) :\codepy - - timeit - - " =open(' :/python /lib/pdb py')"for line in fx=line" close()import timeit min(timeit repeat(number= repeat= stmt=" =open(' :/python /lib/pdb py')\nfor line in fx=line\nf close()")for another example that measures both list comprehensions and pypy' current file speedsee the file listcomp-speed txt in the book examples packageit uses direct pypy command lines to run code from with similar resultspypy' line input is slower today by roughly factor of 'll omit other pythonsoutput here both for space and because these findings could very well change by the time you read these words as usualdifferent types of code can exhibit different types of performance while pypy may optimize much algorithmic codeit may or may not optimize yours you can find additional results in the book' examples packagebut you may be better served by running these tests on your own to verify these findings today or observe their possibly different results in the future the impact of function calls revisited as suggested earliermap also wins for added user-defined functions--the following tests prove the earlier note' claim that map wins the race in cpython if any function must be applied by its alternativesstmts ( "def ( )return \ [ (xfor in 'spam ]")( "def ( )return \nres=[]\nfor in 'spam res append( ( ))")( "def ( )return \ $listif (map( 'spam ))")( "def ( )return \nlist( (xfor in 'spam )") :\codepy - pybench_cases py ( :bd afb ebf sep : : [msc bit (amd ) ["def ( )return \ [ (xfor in 'spam ]" ["def ( )return \nres=[]\nfor in 'spam res append( ( ))" ["def ( )return \nlist(map( 'spam ))" ["def ( )return \nlist( (xfor in 'spam )"compare this with the preceding section' ord teststhough user-defined functions may be slower than built-insthe larger speed hit today seems to be functions in generalwhether they are built-in or not notice that the total time here includes the cost of making helper functionthough only one for every , inner loop repetitions-- negligible factor per both common sense and additional tests run comparing techniqueshomegrown versus batteries for perspectivelet' see how this section' timeit-based results compare to the homegrown-based timer results of the prior sectionby running the file timeseqs py in this timing iterations and pythons with timeit