Watson1978
8/11/2011 - 11:16 PM

bm_reverse.rb

require 'benchmark'

def revcomp(seq)
  seq.reverse!.tr!('wsatugcyrkmbdhvnATUGCYRKMBDHVN','WSTAACGRYMKVHDBNTAACGRYMKVHDBN')
  0.step(seq.size-1,60) {|x| seq.slice(x,60) }
end

Benchmark.bmbm do |x|
  seq = "tgcaacgacatttgaccaacttgaccattcctgcttgtagaccgcgggaactcccctgca" * 1000
  x.report do
    1000.times do
      revcomp(seq)
    end

  end
  puts "objects count = #{ ObjectSpace.each_object{} }"
end
$ ruby19 -v bm_reverse.rb
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0]
objects count = 4839
Rehearsal ------------------------------------
   0.600000   0.000000   0.600000 (  0.598385)
--------------------------- total: 0.600000sec

       user     system      total        real
   0.630000   0.000000   0.630000 (  0.626209)

$ ruby -v bm_reverse.rb 
ruby 1.9.3dev (2011-08-11 revision 32934) [x86_64-darwin11.0.0]
objects count = 7142
Rehearsal ------------------------------------
   1.040000   0.010000   1.050000 (  1.057590)
--------------------------- total: 1.050000sec

       user     system      total        real
   1.010000   0.010000   1.020000 (  1.016697)

$ ruby -v bm_reverse.rb
ruby 1.9.4dev (2011-08-09 trunk 32896) [x86_64-darwin11.0.0]
objects count = 7167
Rehearsal ------------------------------------
   1.110000   0.000000   1.110000 (  1.117300)
--------------------------- total: 1.110000sec

       user     system      total        real
   1.060000   0.000000   1.060000 (  1.070909)
/Users/watson/tmp/bm%