[Python-Dev] redefining is (original) (raw)

Guido van Rossum guido at python.org
Thu Mar 18 13:16:48 EST 2004


Here is a real life example where "is" on immutable objects is very helpful for perfomance reasons

I apreciate that 'is' is faster than '==' for comparing two strings of length 500, but have you tried to measure how much time you are saving in your application?

I doubt it's in the noise. And unless the intern()ed strings are compared over and over, the cost of intern() is mroe than the savings in comparison.

(The best scheme is probably to use intern() but still use '==' for comparisons; '==' is smart enough to skip comparing an object to itself.)

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list