Sha256: c13da9397c7de85cf96698c15e56dbcf2d5ebf6f9c09a0adde77dd0adc64a1a4

Contents?: true

Size: 495 Bytes

Versions: 9

Compression:

Stored size: 495 Bytes

Contents

require "benchmark"
require "string_plus"
str = "federico_martin_iachetti"

[ 1, 10, 100, 1_000, 10_000, 100_000, 1_000_000].each do |n|
  puts ">>>>> n: #{n}"

  Benchmark.bm(20) do |x|
    x.report("split map:") {
      1.upto(n) do
        str.split("_").map(&:capitalize).join
      end
    }
    x.report("gsub:")      {
      1.upto(n) do
        str.gsub(/[a-zA-Z0-9]+/, &:capitalize).gsub("_", "")
      end
    }
    x.report("camelcase:") {
      str.camelcase
    }
  end
  puts
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
string_plus-0.5.3 lib/string_plus/benchmarks.rb
string_plus-0.5.2 lib/string_plus/benchmarks.rb
string_plus-0.5.1 lib/string_plus/benchmarks.rb
string_plus-0.5.0 lib/string_plus/benchmarks.rb
string_plus-0.4.1 lib/string_plus/benchmarks.rb
string_plus-0.4.0 lib/string_plus/benchmarks.rb
string_plus-0.3.1 lib/string_plus/benchmarks.rb
string_plus-0.3.0 lib/string_plus/benchmarks.rb
string_plus-0.2.0 lib/string_plus/benchmarks.rb