News for hackers. Stuff that matters.
Re:PyCon 2011: How Dropbox Did It and How Python Helped by riobard on Sunday March 13, 2011 @06:47PM (#2320464)
Correct me if I got it wrong, but does it mean that putting any Python function in any() makes it run in C???

From my understanding, the any() version is faster is primarily because it avoids looking up .update() method each iteration. The usual Python way of optimizing such cases is:

    # the original slow version
    # 2.87753200531 sec
    def run():
        _md5 = hashlib.md5()
        for i in itertools.repeat("foo", 10000000):
            _md5.update(i)


    # slight change
    # 1.82029104233 sec
    def run():
        _md5 = hashlib.md5()
        update = _md5.update

        for i in itertools.repeat("foo", 10000000):
            update(i)


    # using any()
    # 1.50683498383 sec
    def run():
        _md5 = hashlib.md5()
        any(itertools.imap(_md5.update, itertools.repeat("foo", 10000000)))
Re:PyCon 2011: How Dropbox Did It and How Python Helped by jedsmith on Monday March 14, 2011 @10:31AM (#2322593)
The iterator is consumed in C using any(), instead of the Python bytecode being executed to perform the loop. I don't know if it'd work for "any Python function," but I'd definitely look at it for long-running iterators.