Bearophile wins! (This only times the loop itself. It doesn't check for __len__)
summer:5 0:00:00.000051 bearophile:5 0:00:00.000009 summer:50 0:00:00.000030 bearophile:50 0:00:00.000013 summer:500 0:00:00.000077 bearophile:500 0:00:00.000053 summer:5000 0:00:00.000575 bearophile:5000 0:00:00.000473 summer:50000 0:00:00.005583 bearophile:50000 0:00:00.004625 summer:500000 0:00:00.055834 bearophile:500000 0:00:00.046137 summer:5000000 0:00:00.426734 bearophile:5000000 0:00:00.349573 summer:50000000 0:00:04.180920 bearophile:50000000 0:00:03.652311 summer:500000000 0:00:42.647885 bearophile: 500000000 0:00:35.190550 On Thu, 2009-07-09 at 04:04 -0700, Bearophile wrote: > Paul Rubin: > > print x, sum(1 for _ in g) > > Don't use that, use my function :-) If g has a __len__ you are wasting > time. And sum(1 ...) is (on my PC) slower. > > > J. Clifford Dyer: > > if __name__ == '__main__': > > test_func(summer, 10000000) > > test_func(tupler, 10000000) > > test_func(summer, 100000000) > > test_func(tupler, 100000000) > > Have you forgotten my function? > > Bye, > bearophile -- http://mail.python.org/mailman/listinfo/python-list