Created
November 2, 2011 13:43
-
-
Save sheldonh/1333653 to your computer and use it in GitHub Desktop.
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
#!/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