Index: ceval.c =================================================================== --- ceval.c (revision 53285) +++ ceval.c (working copy) @@ -509,6 +509,21 @@ return PyEval_EvalFrameEx(f, 0); } +#define FAST_TUPLE_ACCESS 1 +#define COUNT_ACCESS 1 + +#if COUNT_ACCESS +static int list_accessed = 0; +static int tuple_accessed = 0; +static int other_accessed = 0; +static int atexit_registered = 0; + +static void final_output(void) +{ + printf("===> list: %d, tuple: %d, other: %d\n", list_accessed, tuple_accessed, other_accessed); +} +#endif + PyObject * PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) { @@ -1173,6 +1188,12 @@ break; case BINARY_SUBSCR: +#if COUNT_ACCESS + if (!atexit_registered) { + atexit_registered = 1; + atexit(final_output); + } +#endif w = POP(); v = TOP(); if (PyList_CheckExact(v) && PyInt_CheckExact(w)) { @@ -1186,10 +1207,33 @@ } else goto slow_get; +#if COUNT_ACCESS + list_accessed++; +#endif } +#if FAST_TUPLE_ACCESS + else if (PyTuple_CheckExact(v) && PyInt_CheckExact(w)) { + /* INLINE: tuple[int] */ + Py_ssize_t i = PyInt_AsSsize_t(w); + if (i < 0) + i += PyTuple_GET_SIZE(v); + if (i >= 0 && i < PyTuple_GET_SIZE(v)) { + x = PyTuple_GET_ITEM(v, i); + Py_INCREF(x); + } + else + goto slow_get; +#if COUNT_ACCESS + tuple_accessed++; +#endif + } +#endif else slow_get: x = PyObject_GetItem(v, w); +#if COUNT_ACCESS + other_accessed++; +#endif Py_DECREF(v); Py_DECREF(w); SET_TOP(x);