Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
This paste will be private.
## benchmark require 'benchmark' total = (ENV['TOTAL'] || 1_000).to_i fixnums = Array.new(total).fill { |a| rand(100_000).to_i } bignums = Array.new(total).fill { |a| 0xffff_ffff_ffff_ffff + rand(100_000).to_i } floats = Array.new(total).fill { |a| rand(100_000).to_f } Benchmark.bmbm do |x| x.report("loop") do times = 0 while times < total i, j = 0, total-1 while i < total i += 1 j -= 1 end times += 1 end end x.report("Fixnum + Fixnum") do times = 0 while times < total i, j = 0, total-1 while i < total fixnums[i] + fixnums[j] i += 1 j -= 1 end times += 1 end end x.report("Bignum + Bignum") do times = 0 while times < total i, j = 0, total-1 while i < total bignums[i] + bignums[j] i += 1 j -= 1 end times += 1 end end x.report("Float + Float") do times = 0 while times < total i, j = 0, total-1 while i < total floats[i] + floats[j] i += 1 j -= 1 end times += 1 end end x.report("Bignum + Fixnum") do times = 0 while times < total i, j = 0, total-1 while i < total bignums[i] + fixnums[j] i += 1 j -= 1 end times += 1 end end x.report("Bignum + Float") do times = 0 while times < total i, j = 0, total-1 while i < total bignums[i] + floats[j] i += 1 j -= 1 end times += 1 end end x.report("Fixnum + Float") do times = 0 while times < total i, j = 0, total-1 while i < total fixnums[i] + floats[j] i += 1 j -= 1 end times += 1 end end end ## MRI euler:rubinius brian$ TOTAL=1_000 ruby math.rb Rehearsal --------------------------------------------------- loop 0.520000 0.000000 0.520000 ( 0.532934) Fixnum + Fixnum 0.940000 0.000000 0.940000 ( 0.953535) Bignum + Bignum 1.230000 0.000000 1.230000 ( 1.228264) Float + Float 0.980000 0.000000 0.980000 ( 0.990313) Bignum + Fixnum 1.440000 0.000000 1.440000 ( 1.457598) Bignum + Float 1.010000 0.010000 1.020000 ( 1.020064) Fixnum + Float 0.970000 0.000000 0.970000 ( 0.975901) ------------------------------------------ total: 7.100000sec user system total real loop 0.510000 0.000000 0.510000 ( 0.525869) Fixnum + Fixnum 0.940000 0.000000 0.940000 ( 0.940014) Bignum + Bignum 1.210000 0.000000 1.210000 ( 1.212178) Float + Float 0.960000 0.000000 0.960000 ( 0.956788) Bignum + Fixnum 1.440000 0.000000 1.440000 ( 1.442112) Bignum + Float 0.990000 0.000000 0.990000 ( 0.998438) Fixnum + Float 0.960000 0.000000 0.960000 ( 0.992699) ## rbx before euler:rubinius brian$ TOTAL=1_000 shotgun/rubinius math.rb Rehearsal --------------------------------------------------- loop 0.088945 0.000000 0.088945 ( 0.088930) Fixnum + Fixnum 0.231998 0.000000 0.231998 ( 0.231984) Bignum + Bignum 0.821572 0.000000 0.821572 ( 0.821547) Float + Float 1.186975 0.000000 1.186975 ( 1.186957) Bignum + Fixnum 3.689706 0.000000 3.689706 ( 3.689688) Bignum + Float 7.798996 0.000000 7.798996 ( 7.798980) Fixnum + Float 7.743594 0.000000 7.743594 ( 7.743577) ----------------------------------------- total: 21.561786sec user system total real loop 0.087257 0.000000 0.087257 ( 0.087245) Fixnum + Fixnum 0.216869 0.000000 0.216869 ( 0.216873) Bignum + Bignum 0.794047 0.000000 0.794047 ( 0.794044) Float + Float 1.174626 0.000000 1.174626 ( 1.174653) Bignum + Fixnum 3.694634 0.000000 3.694634 ( 3.694637) Bignum + Float 7.764805 0.000000 7.764805 ( 7.764801) Fixnum + Float 7.706353 0.000000 7.706353 ( 7.706359) ## rbx after rework Float euler:rubinius brian$ TOTAL=1_000 shotgun/rubinius math.rb Rehearsal --------------------------------------------------- loop 0.091259 0.000000 0.091259 ( 0.091244) Bignum + Bignum 0.814227 0.000000 0.814227 ( 0.814209) Bignum + Fixnum 3.882543 0.000000 3.882543 ( 3.882530) Bignum + Float 7.386961 0.000000 7.386961 ( 7.386945) Fixnum + Fixnum 0.247075 0.000000 0.247075 ( 0.247040) Fixnum + Bignum 3.898931 0.000000 3.898931 ( 3.898914) Fixnum + Float 7.294152 0.000000 7.294152 ( 7.294133) Float + Float 1.288831 0.000000 1.288831 ( 1.288812) Float + Bignum 8.912548 0.000000 8.912548 ( 8.912531) Float + Fixnum 8.871426 0.000000 8.871426 ( 8.871408) ----------------------------------------- total: 42.687953sec user system total real loop 0.088884 0.000000 0.088884 ( 0.088871) Bignum + Bignum 0.788301 0.000000 0.788301 ( 0.788302) Bignum + Fixnum 3.930608 0.000000 3.930608 ( 3.930595) Bignum + Float 7.511396 0.000000 7.511396 ( 7.511508) Fixnum + Fixnum 0.258501 0.000000 0.258501 ( 0.258489) Fixnum + Bignum 3.875360 0.000000 3.875360 ( 3.875369) Fixnum + Float 7.303709 0.000000 7.303709 ( 7.303705) Float + Float 1.294617 0.000000 1.294617 ( 1.294609) Float + Bignum 8.901592 0.000000 8.901592 ( 8.901595) Float + Fixnum 8.865972 0.000000 8.865972 ( 8.865971)
Pasted February 11, 2008 2:10AM EDT
Embed