Permalink
Browse files

Refactoring, and adds startup/throughput

  • Loading branch information...
1 parent 3791d78 commit bbe8a8a6a160a2f120274c52dc066596b9b78b9a @jschementi committed Jan 27, 2009
Showing with 157 additions and 61 deletions.
  1. +12 −2 README
  2. +5 −0 config.rb
  3. 0 empty.rb
  4. +7 −0 loop.rb
  5. +133 −59 stats.rb
View
14 README
@@ -1,10 +1,20 @@
IronRuby-stats
+A script for capturing interesting statistics about IronRuby
+
== Pre-requisites
1. git clone git://github.com/ironruby/ironruby.git
2. Set up IronRuby for building: http://wiki.github.com/ironruby/ironruby
-== Running
+== Configuration
+
+Update config.rb with the path to your IronRuby repository (from step 1 above).
+
+For example, if you ran the "git clone" command in c:/dev, then this would be
+your REPO value:
+
+REPO = 'c:/dev/ironruby'
-ruby stats.rb
+== Usage
+ruby stats.rb [--all] [--build] [--binary] [--repo] [--startup] [--throughput] [-h|--help]
View
5 config.rb
@@ -0,0 +1,5 @@
+#
+# The path on disk to where an IronRuby repository is
+#
+
+REPO = "c:/dev/dlr"
View
0 empty.rb
No changes.
View
7 loop.rb
@@ -0,0 +1,7 @@
+require 'benchmark'
+
+result = Benchmark.measure do
+ $a = 1; 100000.times{|i| $a *= 2}
+end
+
+print result.real
View
192 stats.rb
@@ -1,96 +1,170 @@
-REPO = "c:/dev/dlr"
+load 'config.rb'
RB = "#{REPO}/Merlin/Main/Languages/Ruby"
BIN = "#{REPO}/Merlin/Main/Bin/debug"
+CD = File.expand_path(File.dirname(__FILE__))
require 'fileutils'
require 'mymath'
require 'benchmark'
require 'pp'
#
-# Stat gathering
+# Helpers
#
+require 'net/http'
+require 'uri'
-def build
- puts "Building IronRuby"
- Benchmark.measure do
- FileUtils.cd(RB) { system 'rake compile > nul' }
+module Helpers
+ def fetch(uri_str, limit = 10)
+ raise ArgumentError, 'HTTP redirect too deep' if limit == 0
+
+ response = Net::HTTP.get_response(URI.parse(uri_str))
+ case response
+ when Net::HTTPSuccess then response
+ when Net::HTTPRedirection then fetch(response['location'], limit - 1)
+ else
+ response.error!
+ end
end
-end
-def size_of_binaries
- build unless File.exists? BIN
- Dir["#{BIN}/*.{exe,dll,config}"].
- delete_if { |f| f =~ /ClassInitGenerator|Tests/ }.
- inject({}){ |s, f| s[f] = File.size(f); s }
-end
+ def get_ironruby_from_github
+ print "Downloading IronRuby from GitHub ... "
+ FileUtils.rm 'ironruby.zip' if File.exist?("ironruby.zip")
+ resp = fetch("http://github.com/ironruby/ironruby/zipball/master")
+ size = 0
+ open('ironruby.zip', 'wb') do |file|
+ size = file.write(resp.body)
+ yield 'ironruby.zip' if block_given?
+ end
+ FileUtils.rm 'ironruby.zip'
+ {:size => size, :filename => 'ironruby.zip'}
+ end
+
+ def total_binary_size(binaries)
+ binaries.inject(0){|x,(_,y)| x += y }
+ end
-def github_size
- get_ironruby_from_github[:size]
+ def mb(bytes)
+ bytes./(1_000_000.0).round_to(2)
+ end
end
#
-# Helpers
+# Stat gathering
#
-require 'net/http'
-require 'uri'
-
-def fetch(uri_str, limit = 10)
- raise ArgumentError, 'HTTP redirect too deep' if limit == 0
- response = Net::HTTP.get_response(URI.parse(uri_str))
- case response
- when Net::HTTPSuccess then response
- when Net::HTTPRedirection then fetch(response['location'], limit - 1)
- else
- response.error!
+module Stats
+ include Helpers
+
+ def build
+ Benchmark.measure do
+ FileUtils.cd(RB) { system 'rake compile > nul' }
+ end
end
-end
-def get_ironruby_from_github
- puts "Getting IronRuby from GitHub"
- FileUtils.rm 'ironruby.zip' if File.exist?("ironruby.zip")
- resp = fetch("http://github.com/ironruby/ironruby/zipball/master")
- size = 0
- open('ironruby.zip', 'wb') do |file|
- size = file.write(resp.body)
- yield 'ironruby.zip' if block_given?
+ def size_of_binaries
+ build unless File.exists? BIN
+ Dir["#{BIN}/*.{exe,dll,config}"].
+ delete_if { |f| f =~ /ClassInitGenerator|Tests/ }.
+ inject({}){ |s, f| s[f] = File.size(f); s }
end
- {:size => size, :filename => 'ironruby.zip'}
-end
-def total_binary_size(binaries)
- binaries.inject(0){|x,(_,y)| x += y }
-end
+ def github_size
+ get_ironruby_from_github[:size]
+ end
-def mb(bytes)
- bytes./(1_000_000.0).round_to(2)
+ def startup_time
+ results = nil
+ FileUtils.cd(BIN) do
+ results = Benchmark.measure do
+ `ir #{CD}/empty.rb`
+ end
+ end
+ results
+ end
+
+ def throughput
+ results = nil
+ FileUtils.cd(BIN) do
+ results = `ir #{CD}/loop.rb`
+ end
+ results.to_f
+ end
end
#
# Reporting
#
-def report(type)
- send("report_#{type}")
+class Report
+ class << self
+ include Stats
+ include Helpers
+
+ def run(type)
+ send("report_#{type}")
+ end
+
+ def report_build
+ puts "Build time: #{build.real.round_to(2)} seconds"
+ end
+
+ def report_size_of_binaries
+ puts "Binary size: #{mb(total_binary_size(size_of_binaries))}MB"
+ end
+
+ def report_github_size
+ puts "Github repo size: #{mb(github_size)} MB"
+ end
+
+ def report_startup
+ puts "Startup time: #{startup_time.real.round_to(2)} seconds"
+ end
+
+ def report_throughput
+ puts "Throughput: (100000 iterations) #{throughput.round_to(2)} seconds"
+ end
+
+ def report_all
+ methods.sort.each do |m|
+ if m =~ /report_(.*)/ && $1 != 'all'
+ send(m)
+ end
+ end
+ end
+ end
+
end
-def report_build
- puts "Build time: #{build.real.round_to(2)} seconds"
-end
+#
+# Run the report
+#
-def report_size_of_binaries
- puts "Binary size: #{mb(total_binary_size(size_of_binaries))}MB"
+def help
+ <<-EOS
+usage:
+ ruby stats.rb [--all] [--build] [--binary] [--repo] [--startup] [--throughput] [-h|--help]
+EOS
end
-def report_github_size
- puts "Github repo size: #{mb(github_size)} MB"
+if ARGV.empty?
+ puts help
end
-#
-# Run the report
-#
-
-report :build
-report :size_of_binaries
-report :github_size
+ARGV.each do |arg|
+ case arg
+ when /--help/, /-h/:
+ puts help
+ exit
+ when /--all/ : Report.run :all
+ when /--build/ : Report.run :build
+ when /--binary/ : Report.run :size_of_binary
+ when /--repo/ : Report.run :github_size
+ when /--startup/ : Report.run :startup
+ when /--throughput/ : Report.run :throughput
+ else
+ puts "Unknown argument '#{arg}'"
+ puts help
+ exit
+ end
+end

0 comments on commit bbe8a8a

Please sign in to comment.