Sha256: f1fad918f81ef1764937be8409b66d0ba8c08b7300d723aeb4a2b8289b2b83f4

Contents?: true

Size: 975 Bytes

Versions: 15

Compression:

Stored size: 975 Bytes

Contents

##############################################################################
# Compare File.join vs. Pathname#+
#
# This benchmark was inspired by a post by Thomas Sawyer.  Note that
# Pathname#+ will never be as fast as File.join, but this provides a
# good base for further optimizations.
#
# Also keep in mind that File.join does no path normalization whatsoever,
# e.g. File.join("foo", "/bar") behaves differently than Pathname.new("foo")
# + Pathname.new("/bar").  This is true of both the pathname and pathname2
# packages.
#
# You can run this via the 'rake benchmark_plus' task.
##############################################################################
require 'benchmark'
require 'pathname2'

MAX = 10000

s1 = "a/b/c"
s2 = "d/e/f"

path1 = Pathname.new(s1)
path2 = Pathname.new(s2)

Benchmark.bm(10) do |bench|
   bench.report("File.join"){
      MAX.times{ File.join(s1, s2) }
   }

   bench.report("Pathname#+"){
      MAX.times{ path1 + path2 }
   }
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pathname2-1.8.4 benchmarks/bench_plus.rb
pathname2-1.8.3 benchmarks/bench_plus.rb
pathname2-1.8.2 benchmarks/bench_plus.rb
pathname2-1.8.1 benchmarks/bench_plus.rb
pathname2-1.8.0 benchmarks/bench_plus.rb
pathname2-1.7.4 benchmarks/bench_plus.rb
pathname2-1.7.3 benchmarks/bench_plus.rb
pathname2-1.7.2 benchmarks/bench_plus.rb
pathname2-1.7.1 benchmarks/bench_plus.rb
pathname2-1.7.0 benchmarks/bench_plus.rb
pathname2-1.6.5 benchmarks/bench_plus.rb
pathname2-1.6.4-x86-mingw32 benchmarks/bench_plus.rb
pathname2-1.6.4 benchmarks/bench_plus.rb
pathname2-1.6.3 benchmarks/bench_plus.rb
pathname2-1.6.2 benchmarks/bench_plus.rb