Skip to content

Instantly share code, notes, and snippets.

Created April 1, 2015 12:38
Show Gist options
  • Save anonymous/3ae651fbd3cbb0b74118 to your computer and use it in GitHub Desktop.
Save anonymous/3ae651fbd3cbb0b74118 to your computer and use it in GitHub Desktop.
Calculating -------------------------------------
#gsub 19583 i/100ms
#gsub! 18808 i/100ms
-------------------------------------------------
#gsub 299922.0 (±4.6%) i/s - 1507891 in 5.038274s
#gsub! 281888.2 (±3.9%) i/s - 1410600 in 5.011569s
Comparison:
#gsub: 299922.0 i/s
#gsub!: 281888.2 i/s - 1.06x slower
require 'benchmark/ips'
Benchmark.ips do |bench|
bench.config(time: 5, warmup: 2)
bench.report("#gsub") do
unused = "literalstring".gsub(/era/,'o')
end
bench.report("#gsub!") do
unused = "literalstring".gsub!(/era/,'o')
end
bench.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment