This is not a guaranteed implementation detail for current versions of CPython, so you will not have to rely on it in other Python implementations, including Jython, IronPython, PyPy, and potentially future versions of CPython.
Using is compared to a large list looks like about 0.04 m on my system:
$ python -m timeit -s "x = range(10000)" "x is ()" 10000000 loops, best of 3: 0.0401 usec per loop $ python -m timeit -s "x = range(10000)" "x == ()" 10000000 loops, best of 3: 0.0844 usec per loop
Of course, this could be significantly worse if you are comparing something with the __eq__() custom method:
$ python -m timeit -s $'import time\nclass X(object):\n def __eq__(self, other): return time.sleep(1)\nx = X()' "x == ()" 10 loops, best of 3: 1e+03 msec per loop
However, if this difference in performance is important, I think it will indicate a design problem.
Michael hoffman
source share