tmail/amstd/bench.rb

#
# bench.rb
#
#   Copyright (c) 1999 Minero Aoki <aamine@dp.u-netsurf.ne.jp>
#
#
# usage:
#
#   str = 'test string'
#   benchmark( 'strdup', 10_0000 ) do
#     str = str.dup
#   end
#

def benchmark( label, times, &block )
  begtime = Time.times.utime
  times.times( &block )
  endtime = Time.times.utime
  puts "#{label}: #{endtime - begtime} sec"
end