(test __name__bestofresult[ ]result[- ])this script tests five alternative ways to build lists of results as shownits reported times reflect on the order of million steps for each of the five test functions--each builds list of , items , times this process is repeated times to get the best-of time for each of the test functionsyielding whopping million total steps for the script at large (impressive but reasonable on most machines these daysnotice how we have to run the results of the generator expression and function through the built-in list call to force them to yield all of their valuesif we did notin both and we would just produce generators that never do any real work in python only we must do the same for the map resultsince it is now an iterable object as wellfor xthe list around map must be removed manually to avoid charging an extra list construction overhead per test (though its impact seems negligible in most testsin similar waythe inner loopsrange result is hoisted out to the top of the module to remove its construction cost from total timeand wrapped in list call so that its traversal cost isn' skewed by being generator in only (much as we did in the timer module toothis may be overshadowed by the cost of the inner iterations loopbut it' best to remove as many variables as we can also notice how the code at the bottom steps through tuple of five function objects and prints the __name__ of eachas we've seenthis is built-in attribute that gives function' name timing results when the script of the prior section is run under python get these results on my windows laptop--map is slightly faster than list comprehensionsboth are quicker than for loopsand generator expressions and functions place in the middle (times here are total time in seconds) :\codec:\python \python timeseqs py ( :bd afb ebf sep : : [msc bit (amd )forloop =[ listcomp =[ mapcall =[ genexpr =[ genfunc =[ if you study this code and its output long enoughyou'll notice that generator expressions run slower than list comprehensions today although wrapping generator ex previewnotice how we must pass functions into the timer manually here in and we'll see decorator-based timer alternatives with which timed functions are called normallybut require extra "@syntax where defined decorators may be more useful to instrument functions with timing logic when they are already being used within larger systemand don' as easily support the more isolated test call patterns assumed here--when decoratedevery call to the function runs the timing logicwhich is either plus or minus depending on your goals timing iteration alternatives