def prof(t = 1, output = :puts) starting_time = Time.now t.times { yield } dlta = (Time.now - starting_time).to_f/t case output when :ret "### time: #{dlta.to_s}(s) . req/s: #{(1/dlta)}" else puts "### time: #{dlta.to_s}(s) . req/s: #{(1/dlta)}" end end def run(times, iter) times << ["(1..10).each do |i| puts i end", prof(iter,:ret) { (1..10).each do |i| puts i end }] times << ["for i in (1..10) puts i end ",prof(iter,:ret){ for i in (1..10) puts i end }] times << ["(1..10).each { |i| puts i }",prof(iter,:ret){ (1..10).each { |i| puts i } }] #times << ["puts (1..10).to_a * '\n'",prof(iter,:ret){ # puts (1..10).to_a * "\n" #}] #times << ["puts (1..10).to_a",prof(iter,:ret){ # puts (1..10).to_a #}] times << ["1.upto(10) { |i| puts i }",prof(iter,:ret){ 1.upto(10) { |i| puts i } }] times << ["puts 1,2,3,4,5,6,7,8,9,10",prof(iter,:ret){ puts 1,2,3,4,5,6,7,8,9,10 }] times << ["10.times {|i| p i+1}",prof(iter,:ret){ 10.times {|i| p i+1} }] times << ["p *(1...11)",prof(iter,:ret){ p *(1...11) }] end times = [] # round 1 times << "round 1" run(times, ARGV[0].to_i) # round 2 times << "round 2" run(times, ARGV[0].to_i) puts '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' times.collect { |t| puts t puts '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' }