-
-
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 |
febuiles
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
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)
$ 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)
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)