Skip to content

Instantly share code, notes, and snippets.

@luislavena
Created September 5, 2011 03:01
Show Gist options
  • Select an option

  • Save luislavena/1193978 to your computer and use it in GitHub Desktop.

Select an option

Save luislavena/1193978 to your computer and use it in GitHub Desktop.
require "benchmark"
TESTS = 10_000
puts "File.expand_path: #{TESTS} times."
Benchmark.bmbm do |results|
results.report("Ruby '':") { TESTS.times { File.expand_path('') } }
results.report("Ruby '.':") { TESTS.times { File.expand_path('.') } }
results.report("Ruby 'foo', 'bar':") { TESTS.times { File.expand_path('foo', 'bar') } }
end
Copy link
Copy Markdown

ghost commented Sep 5, 2011

bash-3.00# uname -a
SunOS unknown 5.10 Generic_141445-09 i86pc i386 i86pc

bash-3.00# /opt/csw/bin/ruby -v b.rb
ruby 1.8.7 (2008-06-20 patchlevel 22) [i386-solaris2.8]
File.expand_path: 10000 times.
Rehearsal ------------------------------------------------------
Ruby '':             0.080000   0.090000   0.170000 (  0.210967)
Ruby '.':            0.050000   0.060000   0.110000 (  0.133748)
Ruby 'foo', 'bar':   0.070000   0.060000   0.130000 (  0.133541)
--------------------------------------------- total: 0.410000sec

                         user     system      total        real
Ruby '':             0.050000   0.070000   0.120000 (  0.131280)
Ruby '.':            0.050000   0.070000   0.120000 (  0.129860)
Ruby 'foo', 'bar':   0.070000   0.060000   0.130000 (  0.138462)

Copy link
Copy Markdown

ghost commented Sep 5, 2011

$ uname -a
OpenBSD helios.my.domain 4.8 GENERIC#86 sparc64

$ ruby -v b.rb
ruby 1.8.6 (2009-06-08 patchlevel 369) [sparc64-openbsd4.8]
File.expand_path: 10000 times.
Rehearsal ------------------------------------------------------
Ruby '':             0.280000   0.540000   0.820000 (  0.815368)
Ruby '.':            0.370000   0.430000   0.800000 (  0.799065)
Ruby 'foo', 'bar':   0.380000   0.090000   0.470000 (  0.463137)
--------------------------------------------- total: 2.090000sec

                         user     system      total        real
Ruby '':             0.350000   0.460000   0.810000 (  0.808810)
Ruby '.':            0.360000   0.440000   0.800000 (  0.795507)
Ruby 'foo', 'bar':   0.320000   0.150000   0.470000 (  0.467536)

@blanchma
Copy link
Copy Markdown

blanchma commented Sep 5, 2011

Ubuntu 11.04

$ ruby -v bench.rb
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
File.expand_path: 10000 times.
Rehearsal ------------------------------------------------------
Ruby '': 0.010000 0.070000 0.080000 ( 0.087019)
Ruby '.': 0.020000 0.060000 0.080000 ( 0.083843)
Ruby 'foo', 'bar': 0.020000 0.010000 0.030000 ( 0.031807)
--------------------------------------------- total: 0.190000sec

                     user     system      total        real

Ruby '': 0.020000 0.060000 0.080000 ( 0.074479)
Ruby '.': 0.010000 0.050000 0.060000 ( 0.061989)
Ruby 'foo', 'bar': 0.020000 0.010000 0.030000 ( 0.030194)

$ rvm 1.9.2
$ ruby -v bench.rb
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
File.expand_path: 10000 times.
Rehearsal ------------------------------------------------------
Ruby '': 0.030000 0.020000 0.050000 ( 0.047690)
Ruby '.': 0.030000 0.020000 0.050000 ( 0.061988)
Ruby 'foo', 'bar': 0.040000 0.020000 0.060000 ( 0.058216)
--------------------------------------------- total: 0.160000sec

                     user     system      total        real

Ruby '': 0.020000 0.020000 0.040000 ( 0.046704)
Ruby '.': 0.040000 0.010000 0.050000 ( 0.048023)
Ruby 'foo', 'bar': 0.040000 0.010000 0.050000 ( 0.054152)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment