Revision: 1216 http://trac.macosforge.org/projects/ruby/changeset/1216 Author: lsansonetti@apple.com Date: 2009-03-27 16:24:28 -0700 (Fri, 27 Mar 2009) Log Message: ----------- renamed bench_roxor.rb to old_bench.rb (which will eventually be a separate rake task after) and added a new bench.rb script which will be the basis of the regression performance suite Added Paths: ----------- MacRuby/branches/experimental/bench.rb MacRuby/branches/experimental/old_bench.rb Removed Paths: ------------- MacRuby/branches/experimental/bench_roxor.rb Added: MacRuby/branches/experimental/bench.rb =================================================================== --- MacRuby/branches/experimental/bench.rb (rev 0) +++ MacRuby/branches/experimental/bench.rb 2009-03-27 23:24:28 UTC (rev 1216) @@ -0,0 +1,187 @@ +# A regression performance suite for MacRuby (which doesn't really catch +# regressions yet). +# +# Run with: +# $ ./miniruby -I./lib bench.rb +# +# The same script can also be executed using /usr/bin/ruby or ruby19 to +# compare the implementations. + +def fib(n) + if n < 3 + 1 + else + fib(n-1) + fib(n-2) + end +end + +def tak(x, y, z) + unless y < x + z + else + tak(tak(x-1, y, z), + tak(y-1, z, x), + tak(z-1, x, y)) + end +end + +def tarai(x, y, z) + if x <= y + then y + else tarai(tarai(x-1, y, z), + tarai(y-1, z, x), + tarai(z-1, x, y)) + end +end + +class Class1 + def method1; end + def method2(x); x; end + + def yield1(n); i=0; while i<n; yield; i+=1; end; end + def yield2; yield; end +end + +class Class2 < Class1 + def method1; super; end + def method2(x); super; end +end + +def bench_ivar_read(n) + @obj = 1 + i=0; while i<n; i+=@obj; end +end + +def bench_ivar_write(n) + @obj = 0 + i=0; while i<n; i+=@obj+1; end +end + +ConstantOne = 1 + +require 'benchmark' + +Benchmark.bm(3) do |bm| + + # Fixnum arithmetic. + bm.report('10 fib(30)') do + i=0; while i<10; fib(30); i+=1; end + end + bm.report('10 fib(35)') do + i=0; while i<10; fib(35); i+=1; end + end + bm.report('tak') { tak(18,9,0) } + bm.report('tarai') { tarai(12,6,0) } + + # Loops. + bm.report('10000000 times loop') do + 3000000.times {} + end + bm.report('30000000 times loop') do + 30000000.times {} + end + bm.report('10000000 while loop') do + i=0; while i<10000000; i+=1; end + end + bm.report('60000000 while loop') do + i=0; while i<60000000; i+=1; end + end + + # Messages. + bm.report('30000000 0 arg msg') do + o = Class1.new + i=0; while i<10000000; o.method1; o.method1; o.method1; i+=1; end + end + bm.report('30000000 1 arg msg') do + o = Class1.new + i=0; while i<10000000; o.method2(i); o.method2(i); o.method2(i); i+=1; end + end + bm.report('10000000 0 arg super msg') do + o = Class2.new + i=0; while i<10000000; o.method1; i+=1; end + end + bm.report('10000000 1 arg super msg') do + o = Class2.new + i=0; while i<10000000; o.method2(i); i+=1; end + end + bm.report('10000000 #send') do + o = Class1.new + i=0; while i<10000000; o.send(:method1); i+=1; end + end + + # Instance variables. + bm.report('10000000 ivar read') { bench_ivar_read(10000000) } + bm.report('30000000 ivar read') { bench_ivar_read(30000000) } + bm.report('10000000 ivar write') { bench_ivar_write(10000000) } + bm.report('30000000 ivar write') { bench_ivar_write(30000000) } + + # Const lookup. + bm.report('30000000 const') do + i=0; while i<30000000; i+=ConstantOne; end + end + + # Blocks + bm.report('30000000 yield') do + o = Class1.new + o.yield1(30000000) {} + end + bm.report('30000000 msg w/ block+yield') do + o = Class1.new + i=0; while i<30000000; o.yield2 {}; i+=1; end + end + bm.report('30000000 Proc#call') do + o = proc {} + i=0; while i<30000000; o.call; i+=1; end + end + + # Break + bm.report('30000000 while break') do + i=0; while i<30000000; while true; i+=1; break; end; end + end + bm.report('10000000 block break') do + i=0; while i<10000000; 1.times { i+=1; break }; end + end + + # Next + bm.report('30000000 while next') do + i=0; while i<30000000; i+=1; next; exit; end + end + bm.report('10000000 block next') do + i=0; while i<10000000; 1.times { i+=1; next; exit; }; end + end + + # Exception handlers. + bm.report('60000000 begin w/o exception') do + i=0 + while i<60000000 + begin + i+=1 + rescue + end + end + end + bm.report('60000000 ensure w/o exception') do + i=0 + while i<60000000 + begin + begin + ensure + i+=1 + end + ensure + i+=1 + end + end + end + bm.report('50000 raise') do + i=0 + while i<50000 + begin + raise + rescue + i+=1 + end + end + end + +end Deleted: MacRuby/branches/experimental/bench_roxor.rb =================================================================== --- MacRuby/branches/experimental/bench_roxor.rb 2009-03-27 22:55:46 UTC (rev 1215) +++ MacRuby/branches/experimental/bench_roxor.rb 2009-03-27 23:24:28 UTC (rev 1216) @@ -1,64 +0,0 @@ -core_features = [ - 'bm_app_answer.rb', - 'bm_app_factorial.rb', - 'bm_app_fib.rb', - 'bm_app_raise.rb', - 'bm_app_tak.rb' , - 'bm_app_tarai.rb', - 'bm_app_mergesort.rb', - 'bm_loop_times.rb', - 'bm_loop_whileloop.rb', - 'bm_so_ackermann.rb', -# 'bm_so_nested_loop.rb', - 'bm_so_object.rb', - 'bm_so_random.rb', - 'bm_vm1_block.rb', - 'bm_vm1_const.rb', - 'bm_vm1_ivar.rb', - 'bm_vm1_ivar_set.rb', - 'bm_vm1_ensure.rb', -# 'bm_vm1_length.rb', - 'bm_vm1_rescue.rb', - 'bm_vm1_simplereturn.rb', -# 'bm_vm1_swap.rb', - 'bm_vm2_eval.rb', - 'bm_vm2_poly_method.rb', - 'bm_vm2_proc.rb', - 'bm_vm2_send.rb', - 'bm_vm2_method.rb', - 'bm_vm2_super.rb', - 'bm_vm2_unif1.rb', - 'bm_vm2_zsuper.rb' -] - -def bench(rubies, file, quiet) - rubies.map do |ruby| - $stderr.puts " " + `#{ruby} -v`.strip unless quiet - line = "#{ruby} #{file}" - best = 1e10 - 3.times do - t = Time.now - v = system(line) ? Time.now - t : nil - $stderr.puts " " + v.to_s unless quiet - if v and (best == nil or best > v) - best = v - end - end - [ruby, best] - end -end - -our_ruby = File.join(Dir.pwd, 'miniruby') -rubies = [our_ruby, '/usr/local/bin/ruby19'] -#rubies = [our_ruby, '/usr/local/bin/ruby19', '/usr/bin/ruby'] - -quiet = ARGV[0] == '--quiet' - -Dir.chdir('benchmark') do - core_features.each do |file| - $stderr.puts file + ' ...' - results = bench(rubies, file, quiet) - ok = results.sort { |x, y| x[1] <=> y[1] }[0][0].include?(our_ruby) - $stderr.puts ' ' + (ok ? 'PASS' : 'FAIL') - end -end Copied: MacRuby/branches/experimental/old_bench.rb (from rev 1211, MacRuby/branches/experimental/bench_roxor.rb) =================================================================== --- MacRuby/branches/experimental/old_bench.rb (rev 0) +++ MacRuby/branches/experimental/old_bench.rb 2009-03-27 23:24:28 UTC (rev 1216) @@ -0,0 +1,64 @@ +core_features = [ + 'bm_app_answer.rb', + 'bm_app_factorial.rb', + 'bm_app_fib.rb', + 'bm_app_raise.rb', + 'bm_app_tak.rb' , + 'bm_app_tarai.rb', + 'bm_app_mergesort.rb', + 'bm_loop_times.rb', + 'bm_loop_whileloop.rb', + 'bm_so_ackermann.rb', +# 'bm_so_nested_loop.rb', + 'bm_so_object.rb', + 'bm_so_random.rb', + 'bm_vm1_block.rb', + 'bm_vm1_const.rb', + 'bm_vm1_ivar.rb', + 'bm_vm1_ivar_set.rb', + 'bm_vm1_ensure.rb', +# 'bm_vm1_length.rb', + 'bm_vm1_rescue.rb', + 'bm_vm1_simplereturn.rb', +# 'bm_vm1_swap.rb', + 'bm_vm2_eval.rb', + 'bm_vm2_poly_method.rb', + 'bm_vm2_proc.rb', + 'bm_vm2_send.rb', + 'bm_vm2_method.rb', + 'bm_vm2_super.rb', + 'bm_vm2_unif1.rb', + 'bm_vm2_zsuper.rb' +] + +def bench(rubies, file, quiet) + rubies.map do |ruby| + $stderr.puts " " + `#{ruby} -v`.strip unless quiet + line = "#{ruby} #{file}" + best = 1e10 + 3.times do + t = Time.now + v = system(line) ? Time.now - t : nil + $stderr.puts " " + v.to_s unless quiet + if v and (best == nil or best > v) + best = v + end + end + [ruby, best] + end +end + +our_ruby = File.join(Dir.pwd, 'miniruby') +rubies = [our_ruby, '/usr/local/bin/ruby19'] +#rubies = [our_ruby, '/usr/local/bin/ruby19', '/usr/bin/ruby'] + +quiet = ARGV[0] == '--quiet' + +Dir.chdir('benchmark') do + core_features.each do |file| + $stderr.puts file + ' ...' + results = bench(rubies, file, quiet) + ok = results.sort { |x, y| x[1] <=> y[1] }[0][0].include?(our_ruby) + $stderr.puts ' ' + (ok ? 'PASS' : 'FAIL') + end +end
participants (1)
-
source_changes@macosforge.org