Created
February 27, 2013 20:31
-
-
Save MaximeD/5051426 to your computer and use it in GitHub Desktop.
swap variables
This file contains 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
#!/usr/bin/env ruby | |
a = 2 | |
b = 4 | |
50000000.times do | |
a = a ^ b | |
b = a ^ b | |
a = a ^ b | |
end | |
# 17,97s user 0,01s system 99% cpu 18,005 total | |
c = nil | |
50000000.times do | |
c = a | |
a = b | |
b = c | |
end | |
# 7,16s user 0,01s system 99% cpu 7,180 total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment