Skip to content

Instantly share code, notes, and snippets.

@MaximeD
Created February 27, 2013 20:31
Show Gist options
  • Save MaximeD/5051426 to your computer and use it in GitHub Desktop.
Save MaximeD/5051426 to your computer and use it in GitHub Desktop.
swap variables
#!/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