Skip to content

Instantly share code, notes, and snippets.

@halit
Created December 4, 2012 20:16
Show Gist options
  • Select an option

  • Save halit/4208237 to your computer and use it in GitHub Desktop.

Select an option

Save halit/4208237 to your computer and use it in GitHub Desktop.
Swap value test
def test1(a,b):
a^=b
b^=a
a^=b
return a,b
def test2(a,b):
temp=a
a=b
b=temp
return a,b
if __name__ == '__main__':
import timeit
print(timeit.timeit("test1(1560,9854)", setup="from __main__ import test1"))
print(timeit.timeit("test2(1560,9854)", setup="from __main__ import test2"))
@halit
Copy link
Copy Markdown
Author

halit commented Dec 4, 2012

0.247786045074
0.222108125687

0.246495008469
0.221477031708

0.250215053558
0.224262952805

0.249907970428
0.231054067612

0.246170043945
0.221310853958

0.244709968567
0.223531961441

0.250586986542
0.230588912964

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment