benchmark_suite-master/0000755000175000017500000000000011753232234015676 5ustar avtobiffavtobiffbenchmark_suite-master/History.txt0000644000175000017500000000007611753232234020103 0ustar avtobiffavtobiff=== 1.0.0 / 2011-04-05 * 1 major enhancement * Birthday! benchmark_suite-master/Manifest.txt0000644000175000017500000000025311753232234020205 0ustar avtobiffavtobiff.autotest History.txt Manifest.txt README.txt Rakefile bin/benchmark lib/benchmark/suite-run.rb lib/benchmark/suite.rb lib/benchmark_suite.rb test/test_benchmark_suite.rb benchmark_suite-master/test/0000755000175000017500000000000011753232234016655 5ustar avtobiffavtobiffbenchmark_suite-master/test/test_benchmark_suite.rb0000644000175000017500000000062311753232234023405 0ustar avtobiffavtobiffrequire "test/unit" require "benchmark_suite" class TestBenchmarkSuite < Test::Unit::TestCase def test_ips s = Benchmark::Suite.create do |s| s.quiet! Benchmark.ips(1,1) do |x| x.report("sleep") { sleep(0.25) } end end rep = s.report.first assert_equal "sleep", rep.label assert_equal 4, rep.iterations assert_in_delta 4.0, rep.ips, 0.2 end end benchmark_suite-master/README.md0000644000175000017500000000474311753232234017165 0ustar avtobiffavtobiff# benchmark_suite * http://github.com/evanphx/benchmark_suite ## DESCRIPTION: A set of enhancements to the standard library benchmark.rb ## FEATURES/PROBLEMS: * benchmark/ips - benchmarks a blocks iterations/second. For short snippits of code, ips automatically figures out how many times to run the code to get interesting data. No more guessing at random iteration counts! * benchmark - a cli tool for running multiple benchmarks against multiple rubies. ## SYNOPSIS: ```ruby require 'benchmark/ips' Benchmark.ips do |x| # Typical mode, runs the block as many times as it can x.report("addition") { 1 + 2 } # To reduce overhead, the number of iterations is passed in # and the block must run the code the specific number of times. # Used for when the workload is very small and any overhead # introduces incorrectable errors. x.report("addition2") do |times| i = 0 while i < times 1 + 2 i += 1 end end # To reduce overhead even more, grafts the code given into # the loop that performs the iterations internally to reduce # overhead. Typically not needed, use the |times| form instead. x.report("addition3", "1 + 2") end ``` ## REQUIREMENTS: * ruby-ffi on MRI ## INSTALL: * gem install benchmark_suite ## DEVELOPERS: After checking out the source, run: $ rake newb This task will install any missing dependencies, run the tests/specs, and generate the RDoc. ## LICENSE: (The MIT License) Copyright (c) 2011 Evan Phoenix Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. benchmark_suite-master/Rakefile0000644000175000017500000000052011753232234017340 0ustar avtobiffavtobiff# -*- ruby -*- require 'rubygems' require 'hoe' # Hoe.plugin :compiler # Hoe.plugin :gem_prelude_sucks # Hoe.plugin :inline # Hoe.plugin :inline # Hoe.plugin :racc # Hoe.plugin :rubyforge Hoe.spec 'benchmark_suite' do developer('Evan Phoenix', 'evan@fallingsnow.net') dependency "benchmark-ips", "~> 1.0" end # vim: syntax=ruby benchmark_suite-master/bin/0000755000175000017500000000000011753232234016446 5ustar avtobiffavtobiffbenchmark_suite-master/bin/benchmark0000755000175000017500000000667511753232234020344 0ustar avtobiffavtobiff#!/usr/bin/env ruby require 'optparse' require 'tempfile' lib_path = File.expand_path("../../lib", __FILE__) $:.unshift lib_path require 'benchmark/suite' require 'benchmark/ips' targets = [] extra = [] at_end = false save = false compare_targets = [] opt = OptionParser.new do |o| o.on("-t", "--target TARGET", String, "Use TARGET to compare against: r:ruby|r19:ruby19|x:rbx|j:jruby") do |t| case t when 'r', 'ruby' targets << 'ruby' when 'r19', 'ruby19' targets << 'ruby19' when 'x', 'rbx', 'rubinius' targets << 'rbx' when 'j', 'jruby' targets << 'jruby' else # + disambiguates execution vs using a file if t[0,1] == "+" targets << t[1..-1] elsif File.exists?(t) begin data = Marshal.load(File.read(t)) compare_targets << [t, data] rescue TypeError targets << t end else targets << t end end end o.on("-p", "--profile", "Profile code while benchmarking (rbx only)") do extra << "-Xprofile" end o.on("-e", "--end", "Report all stats after all suitse have run") do at_end = true end o.on("-T OPTION", String, "Add more arguments to each target") do |t| extra << t end o.on("-s", "--save PATH", String, "Save the results to a file") do |t| save = t end end opt.parse! if targets.empty? targets << "ruby" end if save and targets.size > 1 STDOUT.puts "Save mode only available with one target." exit 1 end opts = [] if at_end opts << "--quiet" end results = targets.map do |t| tf = Tempfile.new "benchmark" tf.close STDOUT.puts "=== #{t} ===" unless at_end args = extra + ["-I#{lib_path}", "#{lib_path}/benchmark/suite-run.rb"] args += opts args << tf.path args += ARGV cmd, *rest = t.split(/\s+/) args.unshift *rest system cmd, *args if $?.exitstatus != 0 puts "Error executing: #{cmd}" nil else tf.open [t, Marshal.load(tf.read)] end end results.compact! if save name, data = results.last File.open save, "w" do |f| f << Marshal.dump(data) end STDOUT.puts "[Saved results to '#{save}']" end if at_end results.each do |name, suite| STDOUT.puts "=== #{name} ===" suite.display end end results += compare_targets if results.size > 1 compared = Hash.new { |h,k| h[k] = [] } results.each do |target, suite| suite.reports.each do |name, reports| reports.each do |rep| compared["#{name}:#{rep.label}"] << [target, rep] end end end STDOUT.puts compared.each do |name, reports| if reports.size > 1 STDOUT.puts "Comparing #{name}:" iter = false sorted = reports.sort do |a,b| if a[1].respond_to? :ips iter = true b[1].ips <=> a[1].ips else a[1].runtime <=> b[1].runtime end end best_name, best_report = sorted.shift if iter STDOUT.printf "%20s: %10d i/s\n", best_name, best_report.ips else STDOUT.puts "#{best_name.rjust(20)}: #{best_report.runtime}s" end sorted.each do |entry| name, report = entry if iter x = (best_report.ips.to_f / report.ips.to_f) STDOUT.printf "%20s: %10d i/s - %.2fx slower\n", name, report.ips, x else x = "%.2f" % (report.ips.to_f / best_report.ips.to_f) STDOUT.puts "#{name.rjust(20)}: #{report.runtime}s - #{x}x slower" end end end end end benchmark_suite-master/lib/0000755000175000017500000000000011753232234016444 5ustar avtobiffavtobiffbenchmark_suite-master/lib/benchmark_suite.rb0000644000175000017500000000017411753232234022136 0ustar avtobiffavtobiffrequire 'benchmark/suite' require 'benchmark/ips' require 'benchmark/helpers' class BenchmarkSuite VERSION = '1.0.0' end benchmark_suite-master/lib/benchmark/0000755000175000017500000000000011753232234020376 5ustar avtobiffavtobiffbenchmark_suite-master/lib/benchmark/suite.rb0000644000175000017500000000430411753232234022055 0ustar avtobiffavtobiffrequire 'benchmark' module Benchmark class Suite @current = nil def self.current @current end def self.create if block_given? old = @current begin s = new @current = s yield s return s ensure @current = old end else @current = new end end class SimpleReport def initialize @start = nil @end = nil end attr_reader :start, :end end def initialize @report = nil @reports = {} @order = [] @quiet = false @verbose = false end attr_reader :reports, :report def quiet! @quiet = true end def quiet? @quiet end def warming(label, sec) return unless @verbose STDOUT.print "#{label.rjust(20)} warmup: #{sec}s" end def warmup_stats(time, cycles) return unless @verbose STDOUT.print " time=#{time}us, cycles=#{cycles}." end def running(label, sec) return unless @verbose STDOUT.puts " running: #{sec}s..." end def add_report(rep, location) if @report @report << rep else @report = [rep] end @report_location = location end def run(file) start = Time.now begin load file rescue Exception => e STDOUT.puts "\nError in #{file}:" if e.respond_to? :render e.render else STDOUT.puts e.backtrace end return end fin = Time.now if @report @reports[file] = @report @report = nil else @reports[file] = SimpleReport.new(start, fin) end @order << file end def display if @report file = @report_location ? @report_location.split(":").first : "" @order << file @reports[file] = [@report] end @order.each do |file| STDOUT.puts "#{file}:" reports = @reports[file] if reports.empty? STDOUT.puts " NO REPORTS FOUND" else reports.each do |rep| STDOUT.puts " #{rep}" end end end end end end benchmark_suite-master/lib/benchmark/suite-run.rb0000644000175000017500000000073611753232234022664 0ustar avtobiffavtobiffrequire 'benchmark/suite' require 'optparse' quiet = false opts = OptionParser.new do |o| o.on "-q", "--quiet" do quiet = true end end opts.parse! results = ARGV.shift suite = Benchmark::Suite.create do |s| s.quiet! if quiet ARGV.each do |f| if File.directory?(f) more = Dir["#{f}/**/{bench,bm}_*.rb"] more.each do |x| s.run x end else s.run f end end end File.open(results, "w") { |f| f << Marshal.dump(suite) }