puts <<-HEAD Ruby 1.8 vs. 1.9 Benchmarks

Benchmarks: Ruby 1.8 and Ruby 1.9

using:

Old
Ruby 1.8.6p111 (2007-09-24)
New
Ruby 1.9 revision 13506 (2007-09-23)
System
Mac OS X, MacBook, Core Duo 1.83GHz, 2GB RAM

Please note that these are synthetic benchmarks!

HEAD WIDTH_FACTOR = 400 EXPLAIN = { 'app' => 'Mini apps', 'so' => 'Shootout', 'lib' => 'Libraries', 'vm' => 'Core', 'loop' => 'Loops', 'other' => 'Other', } speedups_for = Hash.new { |h, k| h[k] = [] } looptime = Hash.new([0, 0]) DATA.read.scan(/^(\w+)\s+(\S+)\s+(\S+)\s+(broken|too slow)?/) do |name, old, new, broken| if broken puts "" puts "" % [name] + "" * 2 + "" puts "" next end old = old.to_f new = new.to_f case name when /^loop_whileloop(2)?$/ looptime[$1 || '1'] = [old, new] when /^vm([12])/ offset_old, offset_new = looptime[$1] new -= offset_new old -= offset_old name << '*' end # build HTML table puts "" puts '' % name puts '' % [old, new] puts '' % [ WIDTH_FACTOR * ((new / old) - 1).abs, (new <= old ? 'faster' : 'slower'), (old / new), 100 * ((new / old) - 1) ] puts "" speedup = (old / new) if name[/^(app|loop|so|vm|lib)/] speedups_for[$1] << speedup else speedups_for['other'] << speedup end end puts "
Benchmark old new (in seconds)
%s[#{$4}]
%s%0.1f%0.1f
%0.1fx (%+0.0f %%)
" puts "

* means that results of loop_whileloop/loop_whileloop2 are subtracted.

" puts <<-HTML HTML speedups_for.map do |tag, speedups| average_speedup = speedups.inject { |sum,x| sum + x } / speedups.size [average_speedup, tag, speedups] end.sort.reverse.each do |average_speedup, tag, speedups| puts "" % [speedups.size] puts "" % [average_speedup] end puts "
group # speedup
#{EXPLAIN[tag]} (#{tag})%d%0.1fx
" puts <<-BODY BODY __END__ app_answer 0.631 0.143 app_factorial 0.033 1.111 broken app_fib 7.420 1.953 app_mandelbrot 2.518 1.330 app_pentomino 114.536 58.458 app_raise 2.857 3.646 app_strconcat 1.897 1.337 app_tak 9.548 2.768 app_tarai 7.599 2.089 app_log 2.632 1.737 loop_generator 25.203 1.786 loop_times 6.120 4.501 loop_whileloop 10.415 1.890 loop_whileloop2 2.095 0.395 so_ackermann 13.562 2.038 broken so_array 7.358 4.329 so_concatenate 2.164 1.514 so_count_words 2.199 0.013 broken so_exception 4.885 4.883 so_lists 1.305 1.010 so_matrix 2.303 1.144 so_nested_loop 6.086 3.903 so_object 7.798 5.115 so_random 2.171 0.771 so_sieve 0.702 0.230 vm1_block 24.372 6.858 vm1_const 17.360 2.851 vm1_ensure 17.828 1.938 vm1_length 19.861 5.611 vm1_rescue 12.917 2.120 vm1_simplereturn 21.540 4.686 vm1_swap 26.130 2.633 vm2_array 6.401 3.494 vm2_case 4.887 0.798 vm2_math 6.160 1.039 vm2_method 12.794 5.361 vm2_mutex 5.181 4.059 vm2_new 12.827 8.611 vm2_poly_method 16.537 6.588 vm2_poly_method_ov 4.548 0.896 vm2_proc 7.450 2.363 vm2_regexp 4.683 3.490 vm2_send 4.370 1.160 vm2_super 5.044 1.658 vm2_unif1 3.986 1.111 vm2_zsuper 5.533 1.698 vm3_thread_create_join 0.022 0.155 too slow vm3_thread_mutex 81.659 30.919 lib_coderay 3.186 3.286 lib_json_pure 0.364 0.270 lib_rdoc 4.156 3.332