>>> from timeit import Timer >>> Timer("temp = x; x = y; y = temp", "x = 2; y = 3").timeit() 0.04535215532074004 >>> Timer("x, y = y, x", "x = 2; y = 3").timeit() 0.06476211600816484