Skip to content

Instantly share code, notes, and snippets.

@ascendbruce
Last active December 26, 2015 01:19
Show Gist options
  • Save ascendbruce/7070932 to your computer and use it in GitHub Desktop.
Save ascendbruce/7070932 to your computer and use it in GitHub Desktop.
Ruby performance/benchmark measure methods
# Ruby build-in
require 'benchmark'
puts Benchmark.measure { "a"*1_000_000 } # and Benchmark.bm, Benchmark.bmbm
# handcrafted
def performance
t1 = Time.now.to_f
yield
t2 = Time.now.to_f
return t2 - t1
end
performance {
"a"*1_000_000
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment