Bicycle Repair Man usability

Fredrik Lundh fredrik at pythonware.com
Wed Aug 31 09:22:07 EDT 2005


Kay Schluehr wrote:

> Instead of writing f(g(h(...))) it is sometimes adaequate to write
>
> x = h(...)
> f(g(x))
>
> I use this a lot in particular in C++. Optimzing compilers eliminate
> runtime penalties. This is of course different in CPython.

if "x" is a local variable, the penality isn't that huge:

$ timeit "id(len(str(0)))"
1000000 loops, best of 3: 0.911 usec per loop

$ timeit "x = str(0); id(len(x))"
1000000 loops, best of 3: 0.968 usec per loop

globals are slower:

$ timeit -s "global x" "x = str(0); id(len(x))"
1000000 loops, best of 3: 1.26 usec per loop

</F> 






More information about the Python-list mailing list