:yield: job job = Job.new(width) yield(job) width = job.width sync = STDOUT.sync STDOUT.sync = true # rehearsal print "Rehearsal " puts ’-’*( width+CAPTION.length - "Rehearsal ".length) list = [] job.list.each {|label ,item| print(label.ljust(width)) res = Benchmark :: measure (& item) print res.format () list.push res } sum = Tms.new; list.each {|i| sum += i} ets = sum.format("total: %tsec") printf("%s %s\n\n", "-"*( width+CAPTION.length -ets.length -1) , ets) # take print ’ ’*width , CAPTION list = [] ary = [] job.list.each {|label ,item| GC:: start print label.ljust(width) res = Benchmark :: measure (& item) print res.format () ary.push res list.push [label , res] } STDOUT.sync = sync ary end def benchmark(caption = "", label_width = nil , fmtstr = nil , *labels) # :yield: report sync = STDOUT.sync STDOUT.sync = true label_width ||= 0 fmtstr ||= FMTSTR raise ArgumentError , "no block" unless iterator? print caption results = yield(Report.new(label_width , fmtstr)) Array === results and results.grep(Tms).each {|t| print (( labels.shift || t.label || ""). ljust( label_width ), t.format(fmtstr)) } STDOUT.sync = sync end