Get execution time of XQuery in eXist

405 Views Asked by At

How can I get a reliable measure of the execution time of an XQuery in eXist-db? It seems like eXide takes into account even the render of the results in the browser, am I wrong?

1

There are 1 best solutions below

4
On BEST ANSWER

eXide measures only the time required to execute the query, not to render the results in the browser or serialize the results. (To confirm, see the eXide source where queries are executed and the duration is measured: https://github.com/wolfgangmm/eXide/blob/develop/controller.xql#L155-L193. The first timestamp taken on line 159 and the 2nd on 189-90.)

You can measure the duration of your own queries using this same technique:

xquery version "3.1";

let $start-time := util:system-time()
let $query-needing-measurement := (: insert query or function call here :)
let $end-time := util:system-time()
let $duration := $end-time - $start-time
let $seconds := $duration div xs:dayTimeDuration("PT1S")
return
    "Query completed in " || $seconds || "s."

Another common approach is to log this message or send it to the Monex app's console. For this, use util:log() (built-in) or console:log() (requires Monex, which if not already installed can be installed from the Dashboard > Package Manager).

Also, see the XQuery Wikibook's entry, https://en.wikibooks.org/wiki/XQuery/Timing_a_Query.

Note: Updated with suggestion by Gunther from comments below.