Why are functions atomic?
Alex Martelli
aleax at mac.com
Wed May 2 10:54:38 EDT 2007
Michael <michael.forbes at gmail.com> wrote:
> Is there a reason for using the closure here? Using function defaults
> seems to give better performance:
What measurements show you that...?
brain:~ alex$ cat powi.py
def powerfactory1(exponent):
def inner(x):
return x**exponent
return inner
def powerfactory2(exponent):
def inner(x, exponent=exponent):
return x**exponent
return inner
brain:~ alex$ python -mtimeit -s'import powi; p=powi.powerfactory1(3)'
'p(27)'
1000000 loops, best of 3: 0.485 usec per loop
brain:~ alex$ python -mtimeit -s'import powi; p=powi.powerfactory2(3)'
'p(27)'
1000000 loops, best of 3: 0.482 usec per loop
Alex
More information about the Python-list
mailing list