How do I time queries? - Kdb+ / qStudio

Home Forums Kdb+ / qStudio How do I time queries?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #77

    Dave
    Guest

    How do I time queries? e.g.
    select vwap:size wavg price by date from trade where sym =`RBS
    Is there a query analyser? profiler?

    #129

    admin
    Keymaster

    You can use \t to record how long a query takes:

    q)trade:`date xasc 100000?([] sym:1000?`RBS`o`i; size:1000?1000; price:1000?10.; date:1000?.z.d)
    q)select vwap:size wavg price by date from trade where sym =`RBS
    date | vwap
    ----------| ---------
    2000.01.10| 6.852109
    2000.01.18| 7.724738
    2000.01.22| 7.328888
    2000.01.30| 7.99496
    2000.02.08| 0.8450724
    2000.02.10| 0.276614
    ..
    q)\t select vwap:size wavg price by date from trade where sym =`RBS
    7
    q)\t select vwap:size wavg price by date from trade where sym =`RBS
    4

    To get a reliable timing use a do loop to repeat the action a number of times:

    q)\t do[100; select vwap:size wavg price by date from trade where sym =`RBS]
    238
    q)\t do[100; select vwap:size wavg price by date from trade where sym =`RBS]
    225

    \ts can be used to return both the time taken and the space used in bytes. Alternatively you can use the system format:

    q)\ts do[100; select vwap:size wavg price by date from trade where sym =`RBS]
    219 1772336
    q)system "ts do[100; select vwap:size wavg price by date from trade where sym =`RBS]"
    245 1772336

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.