[MarkLogic Dev General] Faster alternative to fn:last()
Micah.Dubinko at marklogic.com
Fri Jun 22 14:23:35 PDT 2012
An efficient way is to use fn:subsequence instead of a predicate. -m
On Jun 22, 2012, at 2:00 PM, Damon Feldman wrote:
Try subsequence($pageSessionLogs, count($pageSessionLogs), 1)
Anything in square brackets is evaluated once for each element of the sequence, so if you profile that you’ll see something like “postion()=last()” evaluated many times – it just looks like an array index due to a syntactic sugar.
From: general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com> [mailto:general-bounces at developer.marklogic.com] On Behalf Of Danny Sinang
Sent: Friday, June 22, 2012 4:24 PM
Subject: [MarkLogic Dev General] Faster alternative to fn:last()
I'm trying to get the first and last documents in a sequence. The code goes like this :
let $firstLog := $pageSessionLogs
let $lastLog := $pageSessionLogs[fn:last()]
After doing some timings, it looks like the 2nd line always takes around 30 milliseconds. And since I'm doing this in a loop, the delays add up significantly.
Is there a faster way of getting the last sequence member ?
General mailing list
General at developer.marklogic.com<mailto:General at developer.marklogic.com>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the General