How to find out the execution time of KDB requests

I would like to know how long it took to complete the request. I plan to do this for audit and support.

I found this in the documentation:

q)\t log til 100000 / milliseconds for log of first 100000 numbers
3

But the above method actually evaluates the request again and tells us the time. It does not return query results. Therefore, if I use this, it will be like running each request twice, once to get the results, and once to get the runtime information.

Is there any other method that anyone knows about?

+4
source share
3 answers

You can use the "system t" call (equivalent to \ t) to save the result and time at a time.

b:system"t a:log til 100000" 

, .

+2

/ , .

:

q)start:.z.p;result:log til 100000;exectime:.z.p-start 

q)exectime
0D00:00:00.297268000   

q)result 
-0w 0 0.6931472 1.098612 1.386294 ...

- , , \t.

q)res:system"t a:{st:.z.p;log til 10000000;.z.p-st}[]"  
q)`long$`time$a   /convert to Ms
297  
q)res
297
+2

By expanding on the Connor idea, you can wrap it in a function that will return a value and print the time spent on stdout:

time:{ t0:.z.t; r:eval x; 0N!.z.t-t0; :r }

And then send your function parsing tree as an argument:

q)a:time (log;til 100000)
00:00:00.003
q)a
-0w 0 0.6931472 1.098612 1.386294 1.609438 1.791759 1.94591 2.079442 2.197225..
+1
source

Source: https://habr.com/ru/post/1655154/


All Articles