execution time with global variables
Peter Otten
__peter__ at web.de
Fri Jul 2 06:49:00 EDT 2004
Peter Otten wrote:
> As a dumb "better than nothing" recipe I suggest you bundle the globals in
> a Bunch-like class and pass that explicitly to your functions, or convert
> the functions into methods and keep the "global" state as instance
> attributes.
Of course this is even slower:
<time_global.py continued>
class C:
pass
def h(c):
c.x = 1
c.x
c.x
c.x
c.x
c.x
c.x
c.x
c.x
c.x
c.x
</time_global.py>
$ timeit.py -s"from time_global import h, C" -s"c=C()" "h(c)"
1000000 loops, best of 3: 1.94 usec per loop
Peter
More information about the Python-list
mailing list