QStudio
Query kdb+ Servers and Chart Results.
Often I get asked:
First let's create a table t.
1
2
3
4
5
6
q)n:1200300
q)t:([] a:til n; s:n?`3; ex:n?4?`3; size:n?100; price:n?1000.)
q)t
a s ex size price
-----------------------
0 ddd ifb 37 537.5576
To time how long a query takes to run we could use the system t
or \t
command.
Running a command prefixed with \t causes it to return the time that it took to run in milliseconds.
We can then go one step further and use the \t:n
command to run the same query n times and return the total time in milliseconds.
As shown below:
1
2
3
4
5
6
q)select from t where s=`ddd
a s ex size price
---------------------------
0 ddd ifb 37 537.5576
443 ddd ifb 37 383.565
1154 ddd peg 12 385.8024
If we want to profile both how much time and how much memory a query takes to run we can use \ts:n
.
This returns two values, the time taken in milliseconds and the space required in bytes.
1
2
3
4
5
q)\ts select from t where s=`ddd
4 2101600
q)\ts:100 select from t where s=`ddd
298 2101536
One area that we have used this is as part of the qunit test framework for kdb, we log how much memory and time a test takes to run. The framework also allows specifying the maximum time/memory that a unit test should take.
Another interesting idea to try is automatically breaking functions into statements and timing each part, or creating a tool that profiles each line. QStudio provides a basic version of this:
Query kdb+ Servers and Chart Results.