This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2011年07月02日 07:21 by lyricconch, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg139624 - (view) | Author: HaiYun Yan (lyricconch) | Date: 2011年07月02日 07:21 | |
for example: def calc(params): """ i am factoring numbers. """ # an expensive CPU cost function but # passin params and return result are both lightweight cachedcalc = collections.defaultdict(calc) result = cachedcalc[0xFFFFFFFFFFFFFFFFFFF0AC0FFF1] |
|||
| msg139625 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) | Date: 2011年07月02日 08:31 | |
-1. Besides compatibility issues, defaultdict is a dict: it contains data, and is not meant to consume CPU when accessing items. Its "default" function should return initial values, like 0 or an empty list. I think what you want is "memoization"; a memoized function still looks like a function! there are many implementations for python, one of these is here: http://wiki.python.org/moin/PythonDecoratorLibrary#Memoize |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:19 | admin | set | github: 56682 |
| 2011年07月02日 08:31:11 | amaury.forgeotdarc | set | status: open -> closed nosy: + amaury.forgeotdarc messages: + msg139625 resolution: not a bug |
| 2011年07月02日 07:21:09 | lyricconch | create | |