Created
January 30, 2012 23:34
-
-
Save ender672/1707529 to your computer and use it in GitHub Desktop.
String #<< benchmark
This file contains 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
require 'rubygems' | |
require 'benchmark' | |
require 'benchmark/ips' | |
FOO = 'foo' | |
Benchmark.ips do |x| | |
x.report('=') { |times| | |
i = 0 | |
while i < times | |
s = 'bar' | |
s = "#{s}--#{FOO}" | |
i += 1 | |
end | |
} | |
x.report('<<') { |times| | |
i = 0 | |
while i < times | |
s = 'bar' | |
s << "--#{FOO}" | |
i += 1 | |
end | |
} | |
end |
This file contains 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
== 1.9.3-p0 | |
$ ruby bm.rb | |
= 2117084.4 (±1.4%) i/s - 10633565 in 5.023815s (cycle=53435) | |
<< 2716465.9 (±2.4%) i/s - 13593125 in 5.006961s (cycle=56875) | |
== 1.9.2-p290 | |
$ ruby bm.rb | |
= 1870793.2 (±1.3%) i/s - 9384385 in 5.017105s (cycle=54245) | |
<< 2382036.8 (±1.1%) i/s - 11934816 in 5.010962s (cycle=58504) | |
== 1.8.7-p352 | |
$ ruby bm.rb | |
= 1076985.5 (±5.6%) i/s - 5376000 in 5.007787s (cycle=19200) | |
<< 965328.5 (±5.9%) i/s - 4812474 in 5.003429s (cycle=18653) | |
== rbx-1.2.4 | |
$ ruby bm.rb | |
= 6234133.6 (±0.2%) i/s - 31097085 in 4.988210s (cycle=51915) | |
<< 1922727.0 (±0.3%) i/s - 9604609 in 4.995348s (cycle=31909) | |
== jruby-1.6.5 | |
$ jruby bm.rb | |
= 3736923.4 (±2.0%) i/s - 18594728 in 4.977991s (cycle=44168) | |
<< 3157849.3 (±1.8%) i/s - 15793324 in 5.003011s (cycle=56204) | |
== rbx-head | |
$ ruby bm.rb | |
= 5145416.8 (±0.8%) i/s - 25690995 in 4.993268s (cycle=39831) | |
<< 1736795.3 (±1.2%) i/s - 8678054 in 4.997312s (cycle=33506) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment