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