-
-
Save Asher-/709998 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://gist.github.com/709860 | |
require 'benchmark' | |
# does Benchmark::bmbm have environments/setup like Test::Unit | |
# want some variables to be set per benchmark case - now have to dup them myself | |
# is is needed as the testcases have destructive operations, otherwise the testcases will be dependent on each other | |
larger_benchmark = Proc.new do |benchmark| | |
big = (1..95).to_a | |
sml = (75..110).to_a | |
benchmark.report("iterate_larger") { | |
big.each do |big_member| | |
sml.delete_if {|sml_member| sml_member == big_member } | |
end | |
} | |
end | |
diff_benchmark = Proc.new do |benchmark| | |
big = (1..95).to_a | |
sml = (75..110).to_a | |
benchmark.report("set_diff") { sml - big } | |
end | |
smaller_benchmark = Proc.new do |benchmark| | |
big = (1..95).to_a | |
sml = (75..110).to_a | |
benchmark.report("iterate_smaller") { sml.collect { |sml_member| sml_member unless big.include?( sml_member ) }.compact } | |
end | |
benchmark_procs = [ larger_benchmark, diff_benchmark, smaller_benchmark ] | |
benchmark_procs.each do |proc| | |
Benchmark.bmbm( & proc ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment