[Python-Dev] Comparison speed

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Sun, 20 May 2001 15:48:43 +0200


> string_compare() could special-case pointer equality too, although I suspect
> doing so would be a net loss.

I've done some measurements here, too, again taking your example

from time import clock

indices = [1] * 1000000

def doit():
    s = clock()
    for i in indices:
        "ab" < "ab"
    f = clock()
    return f - s

for i in xrange(10):
    print "%.3f" % doit()

This is the case where testing for identity helps. Running it without
identity test takes 0.74s, running it with identity test takes 0.68s.

Now, looking at the case of non-identical pointers, I could not find
any measurable difference. After increasing the number of rounds by a
factor of ten, I got, without identity test

6.920
6.920
6.910
6.970
7.080
6.920
6.920
6.910
6.930
6.920

With identity test, I got

6.930
6.930
6.920
7.080
6.920
6.930
6.960
6.930
6.920
6.920

That still does not look like a significant difference to me.

Regards,
Martin