Permalink
Browse files

version 0.3.3, added multiple modes for :alpha_blend: :source, :dest,…

… :source_with_fixed_alpha, :dest_with_fixed_alpha, also added live and alone
  • Loading branch information...
1 parent 2d7a4f6 commit 3380f8bac7400f36e1ba5ff6329e4f7108e5abeb @banister committed Feb 21, 2011
View
No changes.
View
@@ -20,11 +20,16 @@ def apply_spec_defaults(s)
s.description = s.summary
s.require_path = 'lib'
s.add_dependency("gosu",">=0.7.25")
+ s.add_development_dependency("bacon",">=1.1.0")
s.homepage = "http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/"
s.has_rdoc = 'yard'
- s.files = FileList["Rakefile", "README.markdown", "CHANGELOG",
+ s.files = Dir["Rakefile", "README.markdown", "CHANGELOG",
"lib/**/*.rb", "ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c",
- "examples/*.rb", "examples/media/*", "spec/*.rb"].to_a
+ "examples/*.rb", "examples/media/*", "test/*.rb", "live/*rb", ".gemtest"]
+end
+
+task :test do
+ sh "bacon -k #{direc}/test/texplay_spec.rb"
end
[:mingw32, :mswin32].each do |v|
View
@@ -1,164 +0,0 @@
-direc = File.dirname(__FILE__)
-
-require 'benchmark'
-require "#{direc}/output_format"
-
-module Baseline
- TIME_MODE_DEFAULT = :total
- REPEAT_DEFAULT = 1
-
- @time_mode = TIME_MODE_DEFAULT
- @repeat = REPEAT_DEFAULT
- @output_format = OutputFormat.new
-
- class << self
- attr_accessor :time_mode, :output_format, :repeat
- end
-
- class BenchContext
- attr_reader :total_time, :bench_count,
- :subcontext_count, :repeat
-
- def initialize(repeat, nest_level, before, after)
- @repeat = repeat
- @total_time = 0
- @nest_level = nest_level
- @before = Array(before).dup
- @after = Array(after).dup
- @results = {}
- @bench_count = @subcontext_count = 0
- end
-
- def before(&block)
- @before.push(block)
- end
-
- def after(&block)
- @after.unshift(block)
- end
-
- def exec_hooks(hooks)
- hooks.each do |b|
- instance_eval(&b)
- end
- end
-
- def wrap_with_hooks(options={}, &block)
- exec_hooks(options[:before])
- yield
- exec_hooks(options[:after])
- end
-
- def time_mode
- Module.nesting[1].time_mode
- end
-
- def output_format
- Module.nesting[1].output_format
- end
-
- def exec_bench(name, new_repeat, &block)
- repeat = new_repeat || @repeat
- bm_block = proc { repeat.times { yield } }
-
- time = 0
- wrap_with_hooks(:before => @before, :after => @after) do
- time = Benchmark.measure(&bm_block).send(time_mode)
- @total_time += time
- end
-
- @results[name] = time
- @bench_count += 1
-
- [name, time, new_repeat, :with_own_block]
- end
-
- def show(bench_data, &block)
- case bench_data.last
- when :without_own_block
- name, new_repeat = bench_data
- show exec_bench(name, new_repeat, &block)
- when :with_own_block
- name, time, new_repeat = bench_data
- output_format.bench_output(name, time, new_repeat, @repeat, @nest_level)
- end
- end
-
- def bench(name, options={}, &block)
-
- # if no block then assume block is provided by show method and
- # pass along requisite data so show can do its thing
- if !block_given?
- [name, options[:repeat], :without_own_block]
- else
- exec_bench(name, options[:repeat], &block)
- end
- end
-
- def context(name, options={}, &block)
- return output_format.context_skip(name) if options[:skip]
-
- repeat = options[:repeat] || @repeat
-
- bc = BenchContext.new(repeat, @nest_level + 1, @before, @after)
- bench_count = subcontext_count = 0
- output_format.context_output_header(name, options[:repeat], @repeat, @nest_level)
-
- @total_time += time = bc.tap do |v|
- v.instance_eval(&block)
- bench_count = v.bench_count
- subcontext_count = v.subcontext_count
- end.
- total_time
-
- output_format.context_output_footer(name, time, bench_count, subcontext_count, @nest_level)
- @results[name] = time
- @subcontext_count += 1
- @total_time
- end
-
- def compare(bench1, bench2)
- benches = [bench1, bench2]
- winner, loser = benches.sort_by! { |v| @results[v] }
- time_diff = @results[loser] - @results[winner]
- time_ratio = @results[loser] / @results[winner].to_f
-
- output_format.compare_output(winner, loser, time_diff, time_ratio, @nest_level)
- end
-
- def rank(*names)
- ranking = names.sort_by! { |v| @results[v] }
- output_format.rank_output(ranking, @nest_level)
- end
-end
-
- module ObjectExtensions
- private
- def context(name, options={}, &block)
- return output_format.top_level_context_skip(name) if options[:skip]
-
- repeat = options[:repeat] || Baseline.repeat
- time_mode = Baseline.time_mode
- output_format = Baseline.output_format
-
- output_format.top_level_context_output_header(name, options[:repeat], Baseline.repeat, 0)
- bench_count = subcontext_count = 0
-
- top_level_context_time = Baseline::BenchContext.new(repeat, 1, nil, nil).
- tap do |v|
- v.instance_eval(&block)
- bench_count = v.bench_count
- subcontext_count = v.subcontext_count
- end.
- total_time
-
- output_format.context_output_footer(name, top_level_context_time, bench_count, subcontext_count, 0)
-
- top_level_context_time
- end
- end
-end
-
-class Object
- include Baseline::ObjectExtensions
-end
View
@@ -1,6 +1,7 @@
direc = File.dirname(__FILE__)
-require './bench_context'
+require 'rubygems'
+require 'baseline'
require "#{direc}/../lib/texplay"
include Gosu
@@ -24,6 +25,33 @@
rank "caching false", "caching true"
end
+ context "color_control vs each" do
+ before do
+ @img = TexPlay.create_image(Win, 500, 500)
+ end
+
+ show bench "each" do
+ @img.each do |c|
+ c[0] = 1
+ c[1] *= 0.5
+ c[2] *= 0.5
+ c[3] *= 0.5
+ end
+ end
+
+ show bench "color_control" do
+ @img.clear :color_control => proc { |c|
+ c[0] = 1
+ c[1] *= 0.5
+ c[2] *= 0.5
+ c[3] *= 0.5
+ c
+ }
+ end
+
+ compare "color_control", "each"
+ end
+
context "clear vs filled rec", :repeat => 0, :skip => true do
before do
@img = TexPlay.create_image(Win, 500, 500)
@@ -66,7 +94,7 @@
end
show bench "img.each" do
- @img.each { |v| puts v.inspect }
+# @img.each { |v| puts v.inspect }
end
show bench "gosu color mode" do
@@ -1,58 +0,0 @@
-module Baseline
- class OutputFormat
- def indenter(nest_level)
- " " * 2 * nest_level
- end
-
- def bench_output(name, time, new_repeat, orig_repeat, nest_level)
- repeat = new_repeat || orig_repeat
- repeat_text = new_repeat ? "(repeat: #{repeat})" : ""
- puts "#{indenter(nest_level)}#{name}: %0.2f seconds #{repeat_text}" % time
- end
-
- def context_output_header(name, new_repeat, orig_repeat, nest_level)
- repeat = new_repeat || orig_repeat
- repeat_text = new_repeat ? "(repeat: #{repeat})" : ""
- puts "#{indenter(nest_level)}"
- puts "#{indenter(nest_level)}Benching #{name}: #{repeat_text}"
- end
-
- def context_output_footer(name, time, bench_count, subcontext_count, nest_level)
- puts "#{indenter(nest_level)}Total time: %0.2f seconds for #{name} " \
- "[#{bench_count} benches and #{subcontext_count} subcontexts]" % time
- puts "#{indenter(nest_level)}"
- end
-
- def context_skip(name)
- puts "[Skipping #{name}]"
- end
-
- def top_level_context_skip(name)
- puts "All Benchmarks disabled."
- end
-
- def top_level_context_output_header(name, new_repeat, orig_repeat, nest_level)
- repeat = new_repeat || orig_repeat
- time_mode = Baseline.time_mode
- time_mode_text = time_mode != Baseline::TIME_MODE_DEFAULT ? "(time mode: #{time_mode})" : ""
-
- repeat_text = new_repeat ? "(repeat: #{repeat})" : ""
- puts "#{indenter(nest_level)}"
- puts "#{indenter(nest_level)}Benching #{name}: #{repeat_text} #{time_mode_text}"
- end
-
- def rank_output(ranking, nest_level)
- quoted_ranking = ranking.map.with_index { |v, i| "#{i + 1}. \"#{v}\"" }.join(", ")
- puts "#{indenter(nest_level)}Rankings: #{quoted_ranking}"
- end
-
- def compare_output(winner, loser, time_diff, time_ratio, nest_level)
- if time_diff != 0
- puts "#{indenter(nest_level)}Comparison: \"#{winner}\" is faster than \"#{loser}\"" \
- " by %0.2f seconds (%0.2f times faster)" % [time_diff, time_ratio]
- else
- puts "#{indenter(nest_level)}Comparison: \"#{winner}\" is the same speed as \"#{loser}\""
- end
- end
- end
-end
Oops, something went wrong.

0 comments on commit 3380f8b

Please sign in to comment.