From e028d50b3fcd075c5912575eba91c62b47902c4c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 22 Oct 2014 01:36:43 -0700 Subject: [PATCH] Add benchmark around string replacement. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calculating ------------------------------------- #tr 62416 i/100ms #gsub 33750 i/100ms #gsub! 29695 i/100ms #sub 60774 i/100ms #sub! 64955 i/100ms ------------------------------------------------- #tr 989348.8 (±5.0%) i/s - 4993280 in 5.060836s #gsub 422892.9 (±4.3%) i/s - 2126250 in 5.037741s #gsub! 364115.6 (±4.0%) i/s - 1841090 in 5.064496s #sub 964336.6 (±4.4%) i/s - 4861920 in 5.051775s #sub! 1016598.5 (±4.7%) i/s - 5131445 in 5.058987s --- benchmark/string-replacement | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 benchmark/string-replacement diff --git a/benchmark/string-replacement b/benchmark/string-replacement new file mode 100644 index 00000000..13715376 --- /dev/null +++ b/benchmark/string-replacement @@ -0,0 +1,13 @@ +require 'benchmark/ips' + +def str + 'http://baruco.org/2014/some-talk-with-some-amount-of-value' +end + +Benchmark.ips do |x| + x.report('#tr') { str.tr('some', 'a') } + x.report('#gsub') { str.gsub('some', 'a') } + x.report('#gsub!') { str.gsub!('some', 'a') } + x.report('#sub') { str.sub('some', 'a') } + x.report('#sub!') { str.sub!('some', 'a') } +end