Updated:
- Add split function – time not counted into the total:
bm.log(“label”,:split)
whenever the second parameter is not nil, this time slice is separate from
the total.
- Added sort by time used (longest -> shortest)
- Changed output layout
- Added to RAA
Code…
class Yabm
def initialize
@total=0
@spare=0
@cp=[[nil,Time.now,0]]
end
def log(label=nil,split=nil)
@cp << [label,Time.now,split]
end
def report
elapsed=[]
@cp.each_index do |i|
if @cp[i][0]!=nil then
if @cp[i][2] then
@spare+=@cp[i][1]-@cp[i-1][1]
else
@total+=@cp[i][1]-@cp[i-1][1]
end
elapsed << [@cp[i][0],@cp[i][1]-@cp[i-1][1],@cp[i][2]]
end
end
elapsed.sort! do |x,y| y[1] <=> x[1] end
if @spare==0 then
caption=sprintf “Time used (sec.): %0.3f”,@total
else
caption=sprintf “Time used (sec.): %0.3f / %0.3f”,@total,@total+@spare
end
print “\n”,caption,"\n"
print "-"caption.length,"\n"
elapsed.each do |e|
if e[2] then
printf “%0.3f (----) – %s\n”,e[1],e[0]
else
printf “%0.3f (%0.1f%%) – %s\n”, e[1],e[1]/@total100,e[0]
end
end
end
end
···
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail