Permalink
Browse files

Added new project

[git-p4: depot-paths = "//src/minitest_bench/dev/": change = 5872]
  • Loading branch information...
0 parents commit b06ccac8828daabb4dbbcd395f32507d2a237a7d @zenspider zenspider committed Sep 13, 2010
@@ -0,0 +1,26 @@
+# -*- ruby -*-
+
+require 'autotest/restart'
+
+Autotest.add_hook :initialize do |at|
+ at.testlib = "minitest/autorun"
+ at.add_exception 'tmp'
+
+# at.extra_files << "../some/external/dependency.rb"
+#
+# at.libs << ":../some/external"
+#
+# at.add_exception 'vendor'
+#
+# at.add_mapping(/dependency.rb/) do |f, _|
+# at.files_matching(/test_.*rb$/)
+# end
+#
+# %w(TestA TestB).each do |klass|
+# at.extra_class_map[klass] = "test/test_misc.rb"
+# end
+end
+
+# Autotest.add_hook :run_command do |at|
+# system "rake build"
+# end
@@ -0,0 +1,6 @@
+=== 1.0.0 / 2010-09-10
+
+* 1 major enhancement
+
+ * Birthday!
+
@@ -0,0 +1,11 @@
+.autotest
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+lib/minitest/bench/bacon.rb
+lib/minitest/bench/cucumber.rb
+lib/minitest/bench/minitest.rb
+lib/minitest/bench/rspec.rb
+lib/minitest/bench/shoulda.rb
+lib/minitest/bench/testunit.rb
@@ -0,0 +1,48 @@
+= minitest_bench
+
+* FIX (url)
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+== INSTALL:
+
+* sudo gem install minitest_bench
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) Ryan Davis, seattle.rb
+
+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.
217 Rakefile
@@ -0,0 +1,217 @@
+# -*- ruby -*-
+
+$: << 'lib'
+
+require 'rubygems'
+require 'hoe'
+
+Hoe.plugin :isolate
+Hoe.plugin :seattlerb
+
+class HashHash < Hash
+ def initialize
+ super { |h,k| h[k] = HashHash.new }
+ end
+end
+
+Hoe.spec 'minitest_bench' do
+ developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
+
+ self.version = "1.0.0"
+ self.rubyforge_name = 'seattlerb'
+
+ extra_deps << ["minitest", "> 0"]
+ extra_deps << ["rspec", "> 0"]
+ extra_deps << ["test-unit", "> 0"]
+ extra_deps << ["bacon", "> 0"]
+ extra_deps << ["shoulda", "> 0"]
+ extra_deps << ["cucumber", "> 0"]
+end
+
+task :run => [:generate, :bench, :report]
+
+def test_file path
+ out = "#{path}.out"
+ file path do |t| generate t end
+ file out => path do |t| run_test t end
+ task :clean do rm_f [path, out] end
+ task :generate => path
+ task :bench => out
+end
+
+$units = [10, 100, 1_000, 10_000]
+$types = %w(positive negative)
+$frameworks = []
+
+Gem.find_files("minitest/bench/*.rb").each do |path|
+ require path
+end
+
+$units.each do |n|
+ $types.each do |type|
+ $frameworks.each do |framework|
+ if respond_to? "#{framework}_task" then
+ send "#{framework}_task", framework, type, n
+ else
+ test_file "test/#{framework}_#{type}_#{n}.rb"
+ end
+ end
+ end
+end
+
+task :report do
+ reports = {}
+
+ $units.each do |n|
+ report = Hash.new { |h,k| h[k] = {} }
+
+ Dir["test/*_#{n}.*.out"].sort.each do |path|
+ framework, type, size = test_type path.sub(/\.out$/, '')
+ report[framework][type] = `tail -1 #{path}`.to_f
+ end
+
+ min_p = report.map { |k,v| v["positive"] }.min
+ min_n = report.map { |k,v| v["negative"] }.min
+ max_p = report.map { |k,v| v["positive"] }.max
+ max_n = report.map { |k,v| v["negative"] }.max
+
+ report.each do |framework, h|
+ p_x = h["positive"] / min_p
+ n_x = h["negative"] / min_n
+
+ h["positive_x"] = p_x
+ h["negative_x"] = n_x
+ h["avg_x"] = (p_x + n_x) / 2
+ end
+
+ reports[n] = report
+
+ report = report.sort_by { |k,h| h["avg_x"] }
+
+ cols = %w( positive positive_x negative negative_x avg_x)
+
+ num = report.map { |k,h| [k, *h.values_at(*cols)] }.transpose
+ num.shift # projects
+ records = Hash.new { |h,k| h[k] = {} }
+ cols.zip(num).each do |k, a|
+ records[k][a.min] = "best"
+ records[k][a.max] = "worst"
+ end
+
+ xxx = HashHash.new
+ reports.each do |n, rep|
+ rep.each do |framework, result|
+ result.each do |k,v|
+ next if k =~ /_x$/
+ xxx[k][framework][n] = v
+ end
+ end
+ end
+
+ xxx.each do |type, frameworks|
+ p :type => type
+ frameworks.sort.each do |framework, units|
+ times = units.sort.map { |k,v| v }
+ puts "#{framework}\t#{times.join("\t")}"
+ end
+ puts
+ end
+
+ puts "Size = #{n}:"
+ puts "%15s: %6s (%8s) %6s (%8s) (%8s)" %
+ %w(framework pos multiple neg multiple avg)
+ puts "-" * 63
+ report.each do |framework, h|
+ puts "%15s: %6.2f (%6.2f x) %6.2f (%6.2f x) (%6.2f x)" %
+ [framework, *h.values_at(*cols)]
+ end
+
+ format = ['<tr><th>%s</th>',
+ '<td class="n %s">%.2f</td><td class="x %s">(%.2f x)</td>',
+ '<td class="n %s">%.2f</td><td class="x %s">(%.2f x)</td>',
+ '<td class="x %s">(%.2f x)</td></tr>'].join
+
+ File.open "report.#{n}.html", "w" do |f|
+ f.puts '<?xml version="1.0" encoding="utf-8"?>'
+ f.puts '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" '
+ f.puts ' "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
+ f.puts '<html xmlns="http://www.w3.org/1999/xhtml">'
+ f.puts '<head>'
+ f.puts "<title>Test Framework Benchmark (iter = #{n})</title>"
+ f.puts '<style>'
+ f.puts 'th { text-align: right; }'
+ f.puts 'td { text-align: right; background-color: #eee; }'
+ f.puts 'td.best { background-color: #9f9; }'
+ f.puts 'td.worst { background-color: #f99; }'
+ f.puts '</style>'
+ f.puts '</head>'
+ f.puts '<body>'
+ f.puts '<table>'
+ f.puts "<tr><th>framework</th><th>pos (s)</th><th>multiple</th><th>neg (s)</th><th>multiple</th><th>avg</th></tr>"
+ report.sort_by { |k,h| h["avg_x"] }.each do |framework, h|
+ v = h.values_at(*cols)
+ a = cols.map { |col| records[col][h[col]] }
+ f.puts format % [framework, *a.zip(v).flatten]
+ end
+ f.puts "</table>"
+ end
+ end
+end
+
+############################################################
+# support
+
+def test_type path
+ File.basename(path).sub(/\.(rb|feature)$/, '').split(/_/)
+end
+
+def generate t
+ path = t.name
+ framework, type, size = test_type path
+
+ if respond_to? "generate_#{framework}" then
+ send "generate_#{framework}", path, framework, type, size
+ else
+ mkdir_p File.dirname(path)
+ generic_generate path, framework, type, size
+ end
+end
+
+def generic_generate path, framework, type, size
+ File.open path, "w" do |f|
+ f.puts send "#{framework}_header", type
+ f.puts
+ size.to_i.times do |n|
+ f.puts send "#{framework}_testcase", n, type
+ f.puts
+ end
+
+ f.puts send "#{framework}_footer"
+ end
+end
+
+def run_test t
+ out = t.name
+ path = t.prerequisites.first
+
+ framework, type, size = test_type path
+
+ cmd = case framework
+ when "minitestunit", "minitestspec", "testunit2", "shoulda" then
+ "ruby -rubygems"
+ when "testunit1" then
+ "ruby"
+ when "rspec" then
+ "tmp/isolate/ruby-1.8/bin/spec"
+ when "bacon" then
+ "tmp/isolate/ruby-1.8/bin/bacon"
+ when "cucumber" then
+ "tmp/isolate/ruby-1.8/bin/cucumber --no-color -f progress --require test/cucumber.rb"
+ else
+ raise "unknown framework: #{framework.inspect}"
+ end
+
+ sh "X=1 time #{cmd} #{path} &> #{out}; true"
+end
+
+# vim: syntax=ruby
@@ -0,0 +1,34 @@
+############################################################
+# bacon
+
+require 'minitest/bench/minitest'
+
+def bacon_header type
+ ["require 'bacon'",
+ "",
+ "describe 'Bacon#{type.capitalize}' do",
+ " before do",
+ " @x = rand 1",
+ " end"].join("\n")
+end
+
+def bacon_test type
+ case type
+ when "positive" then
+ "@x.should.equal 0"
+ when "negative" then
+ "@x.should.equal 1"
+ else
+ raise "unknown type: #{type.inspect}"
+ end
+end
+
+def bacon_testcase n, type
+ [" it 'test #{"%04d" % n}' do",
+ " #{bacon_test type}",
+ " end"].join("\n")
+end
+
+alias :bacon_footer :minitestunit_footer
+
+$frameworks << "bacon"
Oops, something went wrong.

0 comments on commit b06ccac

Please sign in to comment.