[MarkLogic Dev General] Faster alternative to fn:last()
Micah Dubinko
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:
Danny,
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.
Yours,
Damon
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
To: general
Subject: [MarkLogic Dev General] Faster alternative to fn:last()
Hello,
I'm trying to get the first and last documents in a sequence. The code goes like this :
let $firstLog := $pageSessionLogs[1]
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 ?
Regards,
Danny
_______________________________________________
General mailing list
General at developer.marklogic.com<mailto:General at developer.marklogic.com>
http://community.marklogic.com/mailman/listinfo/general
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://community.marklogic.com/pipermail/general/attachments/20120622/7a989e64/attachment.html
More information about the General
mailing list