Hi Stevan,
Sounds good! What will this book be focusing on? Will he be releasing soon? Should be a good read!
Hi Vadim,
I find the debug.q script, written by akozyrev, very useful. Located at - http://code.kx.com/wiki/Contrib/debugQ
There is a function in it that splits the function up to each line. Function is .d.rfn, and you should have a look. Using it we can expand on it, and as it is only time execution you are concerned about, then a simple timestamp will suffice.
This (and memory usage per line) would be a good suggestion for the author, and at the bottom of the link above, he asks for suggestions too. Maybe it would be a good idea?
Anyway..here is a quickly written tool for what you require. *Very swiftly tested.
\l debug.q
F:{“{”,x,“}”}
P:{$[“[”=first foo:-1_1_last get x;:@[(foo?/:“”);1;+;1] sublist foo;:“”]}
T:{bar:@[.d.rfn x;where “:”=first each trim each .d.rfn x;1_];raze (“foo:.z.p;”,value bar,:“;foo:foo,.z.p;”),“foo”}
W:{[f;a](enlist each value[.d.rfn get f]),'1_deltas value[F P[get f],T get f] . a}
Wr:{[f;a]foo:W[f;a];`res insert (count[foo]#f;til count foo;foo[;0];foo[;1])}
res:(func:();line:();exe:();timeT:())
Lets define 2 random functions
f:{?[x;();0b;enlist[y]!enlist(sums;y)]}
f2:{[a;b;c;d]a*b;a+b;a*c;a*b*c*d;2000*a*d}
Lets run for each - pass function name and vars as if they were passed into it using “.”
Wr[`f2;(10;20;30;40)]
n:10000000
tab2:(c1:n?1000;c2:n?100.0;c3:n?100.0)
Wr[`f;(`tab2;`c1)]
Lets look at res tab now
q)res
func line exe timeT
f2 0 “a * b;” 0D00:00:00.000000000
f2 1 “a+b;” 0D00:00:00.000000000
f2 2 “a * c;” 0D00:00:00.000000000
f2 3 “a * b * c * d;” 0D00:00:00.000000000
f2 4 “: (2000)* a * d” 0D00:00:00.000000000
f 0 “: ?[x;();0b;(enlist y)!enlist (sums;y)]” 0D00:00:00.046818000
HTH,
Sean