Skip to content

Instantly share code, notes, and snippets.

@kwatch
Created March 2, 2011 02:56
Show Gist options
  • Save kwatch/850386 to your computer and use it in GitHub Desktop.
Save kwatch/850386 to your computer and use it in GitHub Desktop.
benchmark to measure library loading time
###
### benchmark to measure library loading times.
###
require 'rubygems'
require 'benchmarker'
targets = %w[cgi cgi/session erb tempfile tmpdir openssl
logger pathname pstore time date2 uri drb fileutils
rss rexml/document yaml psych rubygems]
if RUBY_VERSION >= '1.9'
targets.delete('date2')
elsif RUBY_VERSION < '1.9'
targets.delete('psych')
end
nloop = 100
#Benchmarker.new(:cycle=>5, :extra=>1) do |bm|
Benchmarker.new() do |bm|
bm.task "ruby" do
nloop.times { system "ruby -e nil" }
end
targets.each do |lib|
bm.task "ruby -r #{lib}" do
nloop.times { system "ruby -r #{lib} -e nil" }
end
end
end
__END__
# benchmarker.rb: release 0.0.0
# RUBY_VERSION: 1.8.7
# RUBY_PATCHLEVEL: 334
# RUBY_PLATFORM: i686-darwin10.6.0
#
# ## Ranking real
# ruby 0.6154 (100.0%) ********************
# ruby -r logger 0.8813 ( 69.8%) **************
# ruby -r pathname 0.9235 ( 66.6%) *************
# ruby -r erb 0.9255 ( 66.5%) *************
# ruby -r rubygems 1.4767 ( 41.7%) ********
# ruby -r drb 1.5176 ( 40.6%) ********
# ruby -r time 1.5904 ( 38.7%) ********
# ruby -r uri 1.6151 ( 38.1%) ********
# ruby -r fileutils 1.7256 ( 35.7%) *******
# ruby -r cgi 1.7312 ( 35.5%) *******
# ruby -r tmpdir 1.7836 ( 34.5%) *******
# ruby -r pstore 1.9187 ( 32.1%) ******
# ruby -r date2 1.9403 ( 31.7%) ******
# ruby -r openssl 2.1919 ( 28.1%) ******
# ruby -r tempfile 2.2530 ( 27.3%) *****
# ruby -r cgi/session 3.0182 ( 20.4%) ****
# ruby -r yaml 3.2269 ( 19.1%) ****
# ruby -r rexml/document 4.0957 ( 15.0%) ***
# ruby -r rss 32.9312 ( 1.9%)
# benchmarker.rb: release 0.0.0
# RUBY_VERSION: 1.9.2
# RUBY_PATCHLEVEL: 180
# RUBY_PLATFORM: x86_64-darwin10.6.0
#
# ## Ranking real
# ruby 1.3350 (100.0%) ********************
# ruby -r erb 2.1582 ( 61.9%) ************
# ruby -r pathname 2.5100 ( 53.2%) ***********
# ruby -r cgi 2.5815 ( 51.7%) **********
# ruby -r logger 2.6093 ( 51.2%) **********
# ruby -r time 3.0882 ( 43.2%) *********
# ruby -r openssl 3.6157 ( 36.9%) *******
# ruby -r fileutils 3.7521 ( 35.6%) *******
# ruby -r tmpdir 3.9069 ( 34.2%) *******
# ruby -r uri 4.3416 ( 30.7%) ******
# ruby -r drb 4.7705 ( 28.0%) ******
# ruby -r pstore 4.8795 ( 27.4%) *****
# ruby -r tempfile 5.3818 ( 24.8%) *****
# ruby -r cgi/session 5.7381 ( 23.3%) *****
# ruby -r yaml 8.1607 ( 16.4%) ***
# ruby -r psych 8.4561 ( 15.8%) ***
# ruby -r rexml/document 10.9415 ( 12.2%) **
# ruby -r rubygems 15.5546 ( 8.6%) **
# ruby -r rss 89.2050 ( 1.5%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment