Skip to content

Instantly share code, notes, and snippets.

@sandyxu
Created November 7, 2014 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandyxu/b300e55826c7d977bf23 to your computer and use it in GitHub Desktop.
Save sandyxu/b300e55826c7d977bf23 to your computer and use it in GitHub Desktop.
benchmark
# need gem install benchmark-ips
require 'benchmark/ips'
def slow(&block)
block.call
end
def fast
yield
end
Benchmark.ips do |x|
x.report("block") { slow { 1 + 1 } }
x.report("yield") { fast { 1 + 1 } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment