Skip to content

Instantly share code, notes, and snippets.

@whoisstan
Created January 2, 2013 20:45
Show Gist options
  • Save whoisstan/4437834 to your computer and use it in GitHub Desktop.
Save whoisstan/4437834 to your computer and use it in GitHub Desktop.
Very Basic benchmark use example to clarify results
require 'benchmark'
require 'benchmark/ips'
Benchmark.ips do |r|
N = 100000
r.report("<< ") do
s = ""
N.times { s << "." }
end
r.report("<< many") do
s = ""
N.times { s << "." << "." << "." << "." << "." << "." << "." }
end
end
Calculating -------------------------------------
<< 4 i/100ms
<< many 1 i/100ms
-------------------------------------------------
<< 41.7 (±2.4%) i/s - 212 in 5.090942s
<< many 8.2 (±0.0%) i/s - 41 in 5.032027s
=> [ << 41.7 (±2.4%) i/s - 212 in 5.090942s, << many 8.2 (±0.0%) i/s - 41 in 5.032027s]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment