iterable without iteratingat the same timeadding this list call in too charges map with an unfair penalty-the map test' results would include the time required to build two listsnot one to work around thisthe script selects map enclosing function per the python version number in sysin xpicking listand in using no-op function that simply returns its input argument unchanged this adds very minor constant time in xwhich is probably fully overshadowed by the cost of the inner loop iterations in the timed function while this makes the comparison between list comprehensions and map more fair in either or xbecause range is also an iterator in xthe results for and won' compare directly unless you also hoist this call out of the timed code they'll be relatively comparable--and will reflect best practice code in each line anyhow--but range iteration adds extra time in only for more on all such thingssee ' benchmark recreationsproducing comparable numbers is often nontrivial task finallyas we did for the tracer decorator earlierwe could make this timing decorator reusable in other modules by indenting the self-test code at the bottom of the file under __name__ test so it runs only when the file is runnot when it' imported we won' do this herethoughbecause we're about to add another feature to our code adding decorator arguments the timer decorator of the prior section worksbut it would be nice if it were more configurable--providing an output label and turning trace messages on and offfor instancemight be useful in general-purpose tool like this decorator arguments come in handy herewhen they're coded properlywe can use them to specify configuration options that can vary for each decorated function labelfor instancemight be added as followsdef timer(label='')def decorator(func)def oncall(*args)func(*argsprint(labelreturn oncall return decorator multilevel state retentionargs passed to function func retained in enclosing scope label retained in enclosing scope @timer('==>'def listcomp( )like listcomp timer('==>')(listcomplistcomp is rebound to new oncall listcompreally calls oncall returns the actual decorator this code adds an enclosing scope to retain decorator argument for use on later actual call when the listcomp function is definedpython really invokes decorator- decorators