Optimizing multiple dispatch

Carl Banks imbosol at aerojockey.com
Fri Jun 4 03:13:08 CEST 2004


Jacek Generowicz <jacek.generowicz at cern.ch> wrote in message news:<tyf1xkwheso.fsf at pcepsft001.cern.ch>...
> Jeff Epler <jepler at unpythonic.net> writes:
> [... Pyrex ...]
> > 100000 loops, best of 3: 2.41 usec per loop
>  [... List comprehension ...]
> > 10000 loops, best of 3: 25.3 usec per loop
>  [... map ...]
> > 100000 loops, best of 3: 17 usec per loop
> 
> (I'm pretty sure that should be 10**5 loops in the list comp case)
> 
> Hmm, ok, the extension seems to be significantly faster. This
> surprises me, because everything that executes in
> "tuple(map(type,args))" is coded in C already, so I don't see where
> the gain is coming from.

Because not all C is the same.  For example, to execute something like
"type(m)", Python has to construct a tuple for the arguments, and call
the type object with it.  The type object new function has some
special casing (to get the behavior of the old type function) and
argument checks and stuff in it.

OTOH, PyObject_Type is probably a macro defined like this:
#define PyObject_Type(_obj) (_obj->ob_type)

So, even though type(m) is "coded in C already", it's not really fast
C.


-- 
CARL BANKS



More information about the Python-list mailing list