Sha256: ea58656c34697727d3e700a9d25febeb7786c629d96bc57033ecaa1c7cf74518

Contents?: true

Size: 625 Bytes

Versions: 5

Compression:

Stored size: 625 Bytes

Contents

require 'benchmark/ips'

Benchmark.ips do |x|
  y = '1_2_3_4_5_6_7_8_9_10'

  x.report('gsub') do |_times|
    y.tr('_', ' ')
  end

  x.report('tr') do |_times|
    y.tr('_', ' ')
  end

  x.compare!
end

__END__

Calculating -------------------------------------
                gsub    29.483k i/100ms
                  tr    79.170k i/100ms
-------------------------------------------------
                gsub     10.420B (±23.7%) i/s -     31.106B
                  tr     78.139B (±20.6%) i/s -    129.289B

Comparison:
                  tr: 78139428607.9 i/s
                gsub: 10419757735.7 i/s - 7.50x slower

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opal-rspec-1.1.0.alpha3 rspec-expectations/upstream/benchmarks/gsub_vs_tr_single_character.rb
opal-rspec-1.1.0.alpha2 rspec-expectations/upstream/benchmarks/gsub_vs_tr_single_character.rb
opal-rspec-1.1.0.alpha1 rspec-expectations/upstream/benchmarks/gsub_vs_tr_single_character.rb
opal-rspec-1.0.0 rspec-expectations/upstream/benchmarks/gsub_vs_tr_single_character.rb
opal-rspec-1.0.0.alpha1 rspec-expectations/upstream/benchmarks/gsub_vs_tr_single_character.rb