Sha256: df0174eddf95bcf95b0826da88073b4a96b34ac2cf4b7692fc9884d16829130d

Contents?: true

Size: 673 Bytes

Versions: 26

Compression:

Stored size: 673 Bytes

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'benchmark/ips'

PATH = '/../../..../...//.....//lorem/ipsum//dolor///sit.xyz'

def sanitize_with_regex
  "/#{PATH.gsub(%r!/{2,}!, '/').gsub(%r{\.+/|\A/+}, '')}"
end

def sanitize_with_builtin
  "/#{PATH}".gsub('..', '/').gsub('./', '').squeeze('/')
end

if sanitize_with_regex == sanitize_with_builtin
  Benchmark.ips do |x|
    x.report('sanitize w/ regexes') { sanitize_with_regex }
    x.report('sanitize w/ builtin') { sanitize_with_builtin }
    x.compare!
  end
else
  puts "w/ regexes: #{sanitize_with_regex}"
  puts "w/ builtin: #{sanitize_with_builtin}"
  puts ''
  puts 'Thank you. Do try again :('
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
lbenicio-minimal-v1-1.6.4 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.6.3 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.6.2 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.6.1 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.5.3 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.5.2 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.5.0 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.4.0 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.3.3 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.3.2 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.3.1 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.3.0 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.2.1 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.2.0 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.1.9 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.1.8 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.1.7 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.1.6 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.1.5 benchmark/sanitize-url.rb
lbenicio-minimal-v1-1.1.4 benchmark/sanitize-url.rb