On Thu, Nov 07, 2013 at 02:30:21PM -0800, Alex Gaynor wrote:

> What is t1 in this context? That's a pretty dramatic slow-down, so I'd like
> to understand it better.

And here's the point where I realise I didn't attach the benchmarks. Mea
culpa. Attached this time (with luck).


Laurie
import time

class t1(object):
    def __eq__(self, o):
        return o == 1

class t2(object):
    def __eq__(self, o):
        return o == 1.0

def bench(l, exp):
    f = eval("lambda: " + exp)
    t = time.time()
    for i in range(1000):
        f()
    print "%s: %.3f" % (exp, time.time() - t)


print "===> Integer lists"
l = []
for i in range(10000000):
    l.append(0)
l.append(1)
bench(l, "1 in l")
bench(l, "'s' in l")
bench(l, "0 in l")
bench(l, "1.0 in l")
bench(l, "1L in l")
bench(l, "object() in l")
bench(l, "t1() in l")
bench(l, "t2() in l")


print "===> Float lists"
l = []
for i in range(10000000):
    l.append(0.8)
l.append(1.0)
bench(l, "1 in l")
bench(l, "'s' in l")
bench(l, "0.8 in l")
bench(l, "1.0 in l")
bench(l, "1L in l")
bench(l, "object() in l")
bench(l, "t1() in l")
bench(l, "t2() in l")
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to