On Wed, May 29, 2002 at 11:00:51AM -0400, Simon Drabble wrote: > I've been profiling some code using Devel::SmallProf, and figured it would be > nice if it displayed the average time for each LoC, in a manner similar to > Devel::DProf. > > SmallProf outputs lines in the form > > > 2 0.000412 0.010000 1:The code for (eval > a b c d e > > where a = the number of times the line was executed, b = the total wall > clock time for the line, c = the total cpu time, d = the line number, and e = > the code itself (or first few characters thereof). > > I'd like to be able to also display b/a in context, directly after field b. > SmallProf also outputs informational lines of the form > > ^L ================ SmallProf version 0.9 ================ > Profile of ./test.pl Page 1 > ================================================================= > count wall tm cpu time line > > these are to be output verbatim. > > > My first attempt: > > perl -p > @_=split;splice@_,0,2,join' ',@_[0..1],$_[1]/$_[0]if$_[0]>0;$_=join' ',@_,"\n" > > for an ugly 81 characters including the -p. > > which was quickly followed by > > -p s#(\d)\s+([\d\.]+)#"$1 $2 ".($1>0?$2/$1:'0')#e; > > for a slightly more respectable 50 characters.
You need \d+ to capture more than single-digit numbers. You don't need single quotes around 0. Don't need the semi-colon at the end. No need to escape . within character class. # 47 chars -p s#(\d+)\s+([\d.]+)#"$1 $2 ".($1>0?$2/$1:0)#e If the number is guaranteed to be non-negative (which I assume it will be): # 45 chars -p s#(\d+)\s+([\d.]+)#"$1 $2 ".($1?$2/$1:0)#e /prakash -- |"It runs like _x, where _x is something unsavory" | | -- Prof. Romas Aleliunas, CS 435 |
