Speed: bytecode vz C API calls

Jacek Generowicz jacek.generowicz at cern.ch
Mon Dec 8 09:45:42 EST 2003


Jacek Generowicz <jacek.generowicz at cern.ch> writes:

> I was expecting C-extensions which make lots of calls to Python C API
> functions, not to be spectacularly fast, but I'm still a little
> disapponited with what I've got. Does this sort of speedup (or rather,
> lack of it) seem right, to those of you experienced with this sort of
> thing? or does it look like I'm doing it wrong?

> static int
> memoize_init(memoizeObject* self, PyObject* args, PyObject* kwds) {
>   PyArg_ParseTuple(args, "O", &(self->fn));

Obvious bug:                    &(self->cache)   !!

>   Py_INCREF(self->fn);
>   self->cache = PyDict_New();
>   return 0;
> }

Fixing the bug gives me a factor of 3 speedup over the class-based
version.

That's a bit more like what I was expecting.




More information about the Python-list mailing list