Created
December 4, 2012 20:16
-
-
Save halit/4208237 to your computer and use it in GitHub Desktop.
Swap value test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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