XQuery/Timing a Query

Motivation
You want to time how long it takes for a query to run.

Method
We will bookend the query with two instances of the util:system-time function.

Example
Our sample query that we want to time is as follows:

To time this query, we will insert util:system-time on either end of the query:

The results of this query will be something like:

0.005

This value is expressed in seconds.

Discussion & Other Approaches
Another approach to timing queries, using higher order functions, is discussed in the article on Timing Fibonacci algorithms.

Also, eXist supports an XQuery pragma for timing queries, which logs the time required to complete a query.

(Explain why util:system-time is necessary and fn:current-time won't work in this example.)