Sha256: 7c9086f513e31b62ce0e2ae4da7a2b4820ffdff8326292a178acaf0e01ea888e

Contents?: true

Size: 1.87 KB

Versions: 43

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true
require 'pathname'
require "benchmark"
require File.dirname(__FILE__) + '/../lib/yard'

pathobj = Pathname.new("a/b/c")
strobj  = "a/b/c"

TIMES = 1_000

log.puts "join:"
Benchmark.bmbm do |x|
  x.report("pathname") { TIMES.times { Pathname.new("a/b/c").join("d", "e", "f") } }
  x.report("string  ") { TIMES.times { File.join("a/b/c", "d", "e", "f") } }
  x.report("pathname-sameobject") { TIMES.times { pathobj.join("d", "e", "f") } }
  x.report("string-sameobject  ") { TIMES.times { File.join(strobj, "d", "e", "f") } }
end

log.puts
log.puts
log.puts "cleanpath:"
Benchmark.bmbm do |x|
  x.report("pathname") { TIMES.times { Pathname.new("a/b//.././c").cleanpath } }
  x.report("string  ") { TIMES.times { File.cleanpath("a/b//.././c") } }
end

__END__
join:
Rehearsal -------------------------------------------------------
pathname              0.330000   0.020000   0.350000 (  0.353481)
string                0.010000   0.000000   0.010000 (  0.001390)
pathname-sameobject   0.360000   0.020000   0.380000 (  0.384473)
string-sameobject     0.000000   0.000000   0.000000 (  0.001187)
---------------------------------------------- total: 0.740000sec

                          user     system      total        real
pathname              0.330000   0.020000   0.350000 (  0.350820)
string                0.000000   0.000000   0.000000 (  0.001055)
pathname-sameobject   0.330000   0.010000   0.340000 (  0.346949)
string-sameobject     0.000000   0.000000   0.000000 (  0.001141)


cleanpath:
Rehearsal --------------------------------------------
pathname   0.060000   0.000000   0.060000 (  0.059767)
string     0.010000   0.000000   0.010000 (  0.013775)
----------------------------------- total: 0.070000sec

               user     system      total        real
pathname   0.060000   0.000000   0.060000 (  0.059697)
string     0.020000   0.000000   0.020000 (  0.013624)

Version data entries

43 entries across 42 versions & 7 rubygems

Version Path
qiita_org-0.1.25 gems/ruby/2.7.0/gems/yard-0.9.25/benchmarks/pathname_vs_string.rb
yard-0.9.25 benchmarks/pathname_vs_string.rb
yard-0.9.24 benchmarks/pathname_vs_string.rb
yard-0.9.23 benchmarks/pathname_vs_string.rb
yard-0.9.22 benchmarks/pathname_vs_string.rb
yard-0.9.21 benchmarks/pathname_vs_string.rb
yard-0.9.20 benchmarks/pathname_vs_string.rb
yard-0.9.19 benchmarks/pathname_vs_string.rb
yard-0.9.16 benchmarks/pathname_vs_string.rb
yard-0.9.15 benchmarks/pathname_vs_string.rb
yard-0.9.14 benchmarks/pathname_vs_string.rb
yard-0.9.13 benchmarks/pathname_vs_string.rb
yard-0.9.12 benchmarks/pathname_vs_string.rb
yard-0.9.11 benchmarks/pathname_vs_string.rb
yard-0.9.10 benchmarks/pathname_vs_string.rb
yard-0.9.9 benchmarks/pathname_vs_string.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.2.0/gems/yard-0.9.8/benchmarks/pathname_vs_string.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.4.0/gems/yard-0.9.8/benchmarks/pathname_vs_string.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/yard-0.9.8/benchmarks/pathname_vs_string.rb
yard-0.9.8 benchmarks/pathname_vs_string.rb