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 Answers
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.

- 5,159
- 16
- 26
-
1`seconds-from-duration($duration)` returns a `mod 60` result, so I'd prefer `$duration div xs:dayTimeDuration("PT1S")` (see https://twitter.com/__Gunther__/status/770338857984327680 :-) ) – Gunther Aug 30 '16 at 20:47
-
Great point. The `seconds-from-duration()` approach would under-report durations of over a minute. I'll update the answer. – Joe Wicentowski Aug 30 '16 at 20:55
-
that code and the eXide popup prints different timing..with a difference even in 0.1s (the popup is always higher) – alfredopacino Aug 31 '16 at 11:01
-
This is probably to be expected. There is some overhead when running queries in eXide. This would be a good question to raise on the exist-open mailing list. – Joe Wicentowski Aug 31 '16 at 12:12