On 05/10/12 01:08, Victor Stinner wrote:
2012/10/4 Steven D'Aprano
: On 04/10/12 21:48, Max Moroz wrote:
It seems that built-in classes do not short-circuit `__eq__` method when the objects are identical, at least in CPython:
f = frozenset(range(200000000)) f1 = f f1 == f # this operation will take about 1 sec on my machine
You shouldn't over-generalize. Some built-ins do short-circuit __eq__ when the objects are identical. I believe that strings and ints both do. Other types might not.
This optimization is not implemented for Unicode strings.
That does not match my experience. In Python 3.2, I generate a large unicode string, and an equal but not identical copy: s = "aĐ–cdef"*100000 t = "a" + s[1:] assert s is not t and s == t Using timeit, s == s is about 10000 times faster than s == t. -- Steven