Skip to content

Instantly share code, notes, and snippets.

@apb2006
Last active December 22, 2015 11:19
Show Gist options
  • Save apb2006/6464619 to your computer and use it in GitHub Desktop.
Save apb2006/6464619 to your computer and use it in GitHub Desktop.
timeout test
let $s:="
import module namespace test = 'org.apb.modules.TestModule';
declare function local:prime($n){
$n = 2 or ($n > 2 and
(every $d in 2 to xs:integer(math:sqrt($n)) satisfies $n mod $d > 0))
};
let $t:=test:startTimeout(xs:int(10000))
return count((1 to 1000000)[local:prime(.)])
"
let $c := client:connect('localhost', 1984, 'admin', 'admin')
return client:query($c,$s)
declare function local:timeit($label,$exp,$timeout){
let $c := client:connect('localhost', 1984, 'admin', 'admin')
let $s:=prof:current-ms()
let $result:=try{
let $c:=client:query($c,$exp,map{'TIMEOUT':=$timeout})
return ()
}catch * {
$err:code
}
return <exec label="{$label}" time="{prof:current-ms()-$s}" result="{$result}"/>
};
let $s:="import module namespace test = 'org.apb.modules.TestModule';
declare function local:prime($n){
$n = 2 or ($n > 2 and
(every $d in 2 to $n idiv 2 satisfies $n mod $d > 0))
};
let $t:=test:startTimeout(xs:int($TIMEOUT))
return count((1 to 100000)[local:prime(.)])"
return local:timeit("prime",$s,20000)
import module namespace test = 'org.apb.modules.TestModule';
declare function local:prime($n){
$n = 2 or ($n > 2 and
(every $d in 2 to xs:integer(math:sqrt($n)) satisfies $n mod $d > 0))
};
let $t:=test:setTimeout(xs:int(5000))
return count((1 to 1000000)[local:prime(.)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment