__autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)
Ralf W. Grosse-Kunstleve
rwgk at yahoo.com
Sat Jul 9 20:42:56 EDT 2005
--- Scott David Daniels <Scott.Daniels at Acm.Org> wrote:
> Should be:
> class autoinit(object):
> def __init__(self, *args, **keyword_args):
> for name, value in zip(self.__autoinit__.im_func.func_code.
> co_varnames[1:], args):
> setattr(self, name, value)
> for name, value in keyword_args.items():
> setattr(self, name, value)
> self.__autoinit__(*args, **keyword_args)
Thanks!
I didn't do it like this out of fear it may be too slow. But it turns out to be
faster:
overhead: 0.00
plain_grouping: 0.27
update_grouping: 0.43
plain_adopt_grouping: 0.68
autoinit_grouping: 1.15
autoinit_setattr_grouping: 1.08 # yours
autoattr_grouping: 1.06
I am amazed. Very good!
Cheers,
Ralf
____________________________________________________
Sell on Yahoo! Auctions no fees. Bid on great items.
http://auctions.yahoo.com/
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: autoinit_timings.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20050709/48c92413/attachment.ksh>
More information about the Python-list
mailing list