No built-in swap function?
Gandalf
gandalf at geochemsource.com
Wed Apr 21 04:51:19 EDT 2004
Josiah Carlson wrote:
>> The xorswap function is not much use for anything other than numbers,
>> however, I would have expected a psyco'ed xorSwap to much faster than
>> the alternatives!
>
>
> You are testing function calling overhead. Try the below...
>
> import time
>
> def tupleswap(a,b):
> t = time.time()
> for i in xrange(100000):
> a,b=b,a;a,b=b,a;a,b=b,a;a,b=b,a;a,b=b,a;
> a,b=b,a;a,b=b,a;a,b=b,a;a,b=b,a;a,b=b,a;
> print "1 million tuple swaps in", time.time()-t, "seconds."
AFAIK, this seems to be 10 thousand instead of 1 million (and 10 mil
instead of 100 mil for
the psyco test).
G
More information about the Python-list
mailing list