[Python-Dev] tuple[int] optimization (original) (raw)
Andrew Svetlov andrew.svetlov at gmail.com
Sun Jul 24 02:15:52 CEST 2011
- Previous message: [Python-Dev] tuple[int] optimization
- Next message: [Python-Dev] tuple[int] optimization
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
You right. Sorry, I missed changes in ceval.c for py3k. Please note, simple test like:
from timeit import timeit
print('list', timeit("l[0]", "l = [1]")) print('tuple', timeit("l[0]", "l = (1,)"))
Has results:
andrew at ocean ~/p/cpython> python2.7 z.py ('list', 0.03479599952697754) ('tuple', 0.046610116958618164)
andrew at ocean ~/p/cpython> python3.2 z.py list 0.04870104789733887 tuple 0.04825997352600098
For python2.7 list[int] microoptimization saves 25-30%, while 3.2 (and trunk) very close to "unoptimized" 2.7 version.
On Sun, Jul 24, 2011 at 2:27 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
On Sun, 24 Jul 2011 09:13:07 +1000 Ryan Kelly <ryan at rfk.id.au> wrote:
In latest trunk this optimisation seems to have gone away, the code is now: TARGET(BINARYSUBSCR) w = POP(); v = TOP(); x = PyObjectGetItem(v, w); PyDECREF(v); PyDECREF(w); SETTOP(x); if (x != NULL) DISPATCH(); break; The implementation of PyObjectGetItem doesn't appear to have changed though. Maybe this optimisation was no longer worth it in practice? The optimization was probably removed because PyInt objects don't exist anymore. There's a related but more ambitious patch at http://bugs.python.org/issue10044. In practice however, such micro-optimizations usually have little or no effect. Regards Antoine.
Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/andrew.svetlov%40gmail.com
- Previous message: [Python-Dev] tuple[int] optimization
- Next message: [Python-Dev] tuple[int] optimization
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]