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