Skip to content

Instantly share code, notes, and snippets.

@luislavena
Created September 5, 2011 03:01
Show Gist options
  • Save luislavena/1193978 to your computer and use it in GitHub Desktop.
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
@phiggins
Copy link

phiggins commented Sep 5, 2011

pete@balloon /tmp $ ruby -v gistfile1.rb 
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
File.expand_path: 10000 times.
Rehearsal ------------------------------------------------------
Ruby '':             0.040000   0.020000   0.060000 (  0.061332)
Ruby '.':            0.030000   0.020000   0.050000 (  0.052420)
Ruby 'foo', 'bar':   0.050000   0.020000   0.070000 (  0.075644)
--------------------------------------------- total: 0.180000sec

                         user     system      total        real
Ruby '':             0.040000   0.030000   0.070000 (  0.062497)
Ruby '.':            0.040000   0.020000   0.060000 (  0.067100)
Ruby 'foo', 'bar':   0.050000   0.020000   0.070000 (  0.071317)
pete@balloon /tmp $ uname -a
Linux balloon 3.0.3-gentoo #5 SMP Tue Aug 23 16:45:24 PDT 2011 x86_64 Intel(R) Core(TM) i7-2720QM CPU @ 2.20GHz GenuineIntel GNU/Linux

Copy link

ghost commented Sep 5, 2011

Mac-mini:tmp frank$ uname -a
Darwin Mac-mini.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386

Mac-mini:tmp frank$ ruby -v b.rb 
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
File.expand_path: 10000 times.
Rehearsal ------------------------------------------------------
Ruby '':             0.030000   0.090000   0.120000 (  0.127861)
Ruby '.':            0.040000   0.090000   0.130000 (  0.120604)
Ruby 'foo', 'bar':   0.040000   0.090000   0.130000 (  0.127145)
--------------------------------------------- total: 0.380000sec

                         user     system      total        real
Ruby '':             0.030000   0.080000   0.110000 (  0.121395)
Ruby '.':            0.040000   0.090000   0.130000 (  0.120622)
Ruby 'foo', 'bar':   0.040000   0.090000   0.130000 (  0.127611)

Mac-mini:tmp frank$ /usr/local/bin/ruby -v b.rb 
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
File.expand_path: 10000 times.
Rehearsal ------------------------------------------------------
Ruby '':             0.050000   0.100000   0.150000 (  0.149669)
Ruby '.':            0.050000   0.090000   0.140000 (  0.144452)
Ruby 'foo', 'bar':   0.060000   0.090000   0.150000 (  0.152170)
--------------------------------------------- total: 0.440000sec

                         user     system      total        real
Ruby '':             0.050000   0.090000   0.140000 (  0.137654)
Ruby '.':            0.050000   0.090000   0.140000 (  0.139227)
Ruby 'foo', 'bar':   0.060000   0.090000   0.150000 (  0.153716)

Mac-mini:tmp frank$ jruby -v b.rb 
jruby 1.6.4 (ruby-1.8.7-p330) (2011-08-23 17ea768) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]
File.expand_path: 10000 times.
Rehearsal ------------------------------------------------------
Ruby '':             1.734000   0.000000   1.734000 (  1.177000)
Ruby '.':            0.172000   0.000000   0.172000 (  0.172000)
Ruby 'foo', 'bar':   0.150000   0.000000   0.150000 (  0.150000)
--------------------------------------------- total: 2.056000sec

                         user     system      total        real
Ruby '':             0.012000   0.000000   0.012000 (  0.011000)
Ruby '.':            0.014000   0.000000   0.014000 (  0.014000)
Ruby 'foo', 'bar':   0.029000   0.000000   0.029000 (  0.029000)

@spastorino
Copy link

➜  /tmp  ruby -v bench.rb
ruby 1.9.3dev (2011-09-02 revision 33165) [x86_64-darwin10.8.0]
File.expand_path: 10000 times.
Rehearsal ------------------------------------------------------
Ruby '':             0.030000   0.050000   0.080000 (  0.081550)
Ruby '.':            0.020000   0.060000   0.080000 (  0.083036)
Ruby 'foo', 'bar':   0.040000   0.050000   0.090000 (  0.089573)
--------------------------------------------- total: 0.250000sec

                         user     system      total        real
Ruby '':             0.020000   0.060000   0.080000 (  0.079781)
Ruby '.':            0.030000   0.050000   0.080000 (  0.079985)
Ruby 'foo', 'bar':   0.040000   0.060000   0.100000 (  0.089250)

@febuiles
Copy link

febuiles commented Sep 5, 2011

 ~
 uname -a
 Darwin Macintosh.local 11.1.0 Darwin Kernel Version 11.1.0: Tue Jul 26 16:07:11 PDT 2011; root:xnu-1699.22.81~1/RELEASE_X86_64 x86_64

 ~
 $ ruby -v foo.rb
 ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
 File.expand_path: 10000 times.
 Rehearsal ------------------------------------------------------
 Ruby '':             0.040000   0.090000   0.130000 (  0.137891)
 Ruby '.':            0.050000   0.080000   0.130000 (  0.125512)
 Ruby 'foo', 'bar':   0.060000   0.080000   0.140000 (  0.144164)
 --------------------------------------------- total: 0.400000sec

                          user     system      total        real
 Ruby '':             0.040000   0.080000   0.120000 (  0.129342)
 Ruby '.':            0.050000   0.090000   0.140000 (  0.125067)
 Ruby 'foo', 'bar':   0.060000   0.080000   0.140000 (  0.144558)

@inkel
Copy link

inkel commented Sep 5, 2011

~/dev/1193978 ruby-1.9.2-p180
(master) >> rvm 1.9.2 ruby gistfile1.rb
File.expand_path: 10000 times.
Rehearsal ------------------------------------------------------
Ruby '':             0.040000   0.020000   0.060000 (  0.063244)
Ruby '.':            0.040000   0.020000   0.060000 (  0.058842)
Ruby 'foo', 'bar':   0.050000   0.040000   0.090000 (  0.083166)
--------------------------------------------- total: 0.210000sec

                         user     system      total        real
Ruby '':             0.040000   0.020000   0.060000 (  0.058373)
Ruby '.':            0.050000   0.010000   0.060000 (  0.064511)
Ruby 'foo', 'bar':   0.050000   0.030000   0.080000 (  0.081027)

~/dev/1193978 ruby-1.9.2-p180
(master) >> rvm 1.8.7 ruby gistfile1.rb
File.expand_path: 10000 times.
Rehearsal ------------------------------------------------------
Ruby '':             0.020000   0.010000   0.030000 (  0.029621)
Ruby '.':            0.010000   0.010000   0.020000 (  0.024228)
Ruby 'foo', 'bar':   0.020000   0.010000   0.030000 (  0.028622)
--------------------------------------------- total: 0.080000sec

                         user     system      total        real
Ruby '':             0.000000   0.030000   0.030000 (  0.029421)
Ruby '.':            0.000000   0.030000   0.030000 (  0.029499)
Ruby 'foo', 'bar':   0.020000   0.010000   0.030000 (  0.027104)

~/dev/1193978 ruby-1.9.2-p180
(master) >> uname -a
Linux roke 2.6.38-11-generic #48-Ubuntu SMP Fri Jul 29 19:02:55 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

Copy link

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

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

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