dictionary.update() enhancement?

Erik Max Francis max at alcyone.com
Fri Oct 12 23:45:54 CEST 2001


Cliff Wells wrote:

> On Friday 12 October 2001 12:04, Erik Max Francis wrote:
>
> > Mark J wrote:
> >
> > > Because it's not as straight-forward as saying d.update(other,
> > > collision_handler) and it's about 10 times slower.
> >
> > Ten times slower?  What in the world gives you that idea?
> 
> Especially since d.update(other, collision_handler)  doesn't exist and
> hence
> can't be benchmarked.

Indeed.  The only way to speed up such a thing is to make the logic
(iterating through the items in the second list and testing if there is
a collision) written in C, but the thing that's going to take up the
most time here is invocations of the user-supplied function, which will
be Python.  One can optimize the former, but will get almost no benefit
since the latter will be the bottleneck.  Further, any such benefit will
only be noticeable if there are a huge amount of items or this updating
is being done very frequently.  I wouldn't say that's a significant
issue; "lightning fast" is plenty good enough for most applications.

In other words, no, it will not be 1000% slower.  I would be surprised
if it were even 10% slower.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Too much agreement kills a chat.
\__/ Eldridge Cleaver
    Computer science / http://www.alcyone.com/max/reference/compsci/
 A computer science reference.



More information about the Python-list mailing list