#21351: memoize function needs tests and improvements
--------------------------------------+------------------------------------
Reporter: EvilDMP | Owner: bouke
Type: Cleanup/optimization | Status: assigned
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by bouke):
I have attached a rewritten speedtest, which should show the performance
impact on 1M reads and writes. `lru_cache` is around 3 times slower on
both, which should come as no surprise. `memoize` has a very simplistic
cache key generator as it copies positional arguments into a new list,
while `lru_cache` creates a hash of both positional and keyword arguments.
This overhead comes at a reduced performance. Nevertheless looking at the
performance difference of a single read (0.0000006s) and write
(.0000014s), the impact seems rather limited.
{{{
Python: 2.7.5 (default, Sep 5 2013, 23:32:22) [GCC 4.2.1 Compatible Apple
LLVM 4.2 (clang-425.0.28)]
+-----------+----------+-----------+
| | memoize | lru_cache |
+-----------+----------+-----------+
| 1M reads | 0.34065s | 1.07396s |
| 1M writes | 1.01192s | 2.71383s |
+-----------+----------+-----------+
Python: 3.3.2 (default, Nov 6 2013, 08:59:42) [GCC 4.2.1 Compatible Apple
LLVM 5.0 (clang-500.2.79)]
+-----------+----------+-----------+
| | memoize | lru_cache |
+-----------+----------+-----------+
| 1M reads | 0.30876s | 0.87845s |
| 1M writes | 0.99767s | 2.39997s |
+-----------+----------+-----------+
}}}
The PR has been updated with the redundant tests removed and PY3
compatibility.
--
Ticket URL: <https://code.djangoproject.com/ticket/21351#comment:14>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.1308200fc38298f96b95917b2816e98e%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.