[Python-Dev] Faster Set.discard() method?

Andrew McNamara andrewm at object-craft.com.au
Fri Mar 18 06:44:23 CET 2005


>> But the dict.pop method is about 12 times faster. Is this worth doing?
>
>The 2.4 builtin set's discard function looks like it does roughly the same
>as the 2.3 sets.Set.  Have you tried comparing a C version of your version
>with the 2.4 set to see if there are speedups there, too?

Ah. I had forgotten it was builtin - I'd found the python implementation
and concluded the C implementation didn't make it into 2.4 for some
reason... 8-)

Yes, the builtin set.discard() method is already faster than dict.pop().

>IMO keeping the sets.Set version as clean and readable as possible is nice,
>since the reason this exists is for other implementations (Jython, PyPy,
>...) and documentation, right?  OTOH, speeding up the CPython implementation
>is nice and it's read by many fewer people.

No, you're right - making sets.Set less readable than it already is would
be a step backwards. On the other hand, Jython and PyPy are already in
trouble - the builtin set() is not entirely compatible with sets.Set.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/


More information about the Python-Dev mailing list