Optimising list comparison

Skip Montanaro skip at pobox.com
Fri Mar 15 16:41:46 EST 2002


    Graham> A friend of mine is using Python in a research project where he
    Graham> needs to compare each element of two vectors, such that ...

    Graham> Now, having read Skip M's python optimisation page ...

which is getting quite dated... ;-)

    Graham> Neither of us have yet managed to come up with anything to beat
    Graham> it (we've been timing the alternatives over 100000 itterations).

    Graham> Any hints?

Psyco <http://sourceforge.net/projects/psyco>.  I added these lines at the
end of your benchmark script:

    import psyco
    psyco.bind(attempt1)
    psyco.bind(attempt2)
    benchmark(attempt1)
    benchmark(attempt2)

and ran it again.  I got

    100000 iterations of <function attempt1 at 0x811a914> took: 8.673 secs
    100000 iterations of <function attempt2 at 0x8132e94> took: 19.812 secs
    100000 iterations of <function attempt1 at 0x811a914> took: 1.546 secs
    100000 iterations of <function attempt2 at 0x8132e94> took: 20.121 secs

die-map-die-ly, yr's,

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)




More information about the Python-list mailing list