Skip to content

Instantly share code, notes, and snippets.

@sheldonh
Created November 2, 2011 13:43
Show Gist options
  • Save sheldonh/1333653 to your computer and use it in GitHub Desktop.
Save sheldonh/1333653 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# output
#
# 17.340000 0.000000 17.340000 ( 17.346691)
# 18.380000 0.000000 18.380000 ( 18.388277)
#
require 'benchmark'
def bitmask
2 ** 32 - 1
end
def bitmask_with_assignment
overshoot = 2 ** 32
overshoot - 1
end
iterations = 10_000_000
iterations.times { b = bitmask }
puts Benchmark.measure { iterations.times { b = bitmask } }
iterations.times { b = bitmask_with_assignment }
puts Benchmark.measure { iterations.times { b = bitmask_with_assignment } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment