From: Shannon Fang Date: 2002-12-19T09:23:47+09:00 Subject: yet another benchmark Hi, Inspired by the benchmark module, I wrote "yet another benchmark". The benefit of the code: 1. simple :) 2. does not interfere with program output. Usage: require "yabm.rb" bm=Yabm.new ... bm.log("Task1") ... bm.log ... bm.log("Task2") ... bm.log("Task3") bm.report The log method is called after the task has finished. A log call with no argument will record the start time of a task, otherwise, the start time of a task is same as the finish time of last task. yabm.rb: class Yabm def initialize @cp=[] @cp << [nil,Time.now] end def log(label=nil) @cp << [label,Time.now] end def report total=@cp[@cp.length-1][1]-@cp[0][1] caption="Time used: %0.2f sec."%total print "\n",caption,"\n" print "-"*caption.length,"\n" @cp.each_index do |i| if @cp[i][0]!=nil then elapsed=@cp[i][1]-@cp[i-1][1] printf "%s: %0.2f sec. (%0.2f%%)\n", @cp[i][0],elapsed,elapsed/total*100 end end end end A moron question: what is the meaning of "user time" and "system time"? Is it useful when doing benchmarking? Thanks... Shannon