Skip to content

Instantly share code, notes, and snippets.

@line-o
Created February 24, 2021 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save line-o/03859f0e73429795166225ad14e11351 to your computer and use it in GitHub Desktop.
Save line-o/03859f0e73429795166225ad14e11351 to your computer and use it in GitHub Desktop.
Performance comparison of filtering atomics in list A not contained in list B
xquery version "3.1";
declare variable $local:millisecond := xs:dayTimeDuration('PT0.001S');
declare variable $local:max := 3000;
declare variable $local:reference := for-each(1 to $local:max, xs:string(?));
declare variable $local:test := for-each((3 to 400, 402 to 2900), xs:string(?));
declare function local:one () {
let $as-map :=
for-each($local:test, function ($k) {
map { $k : true() }
})
=> map:merge()
let $filter-fun := function ($i) { not(map:contains($as-map, $i)) }
return filter($local:reference, $filter-fun)
};
declare function local:two () {
$local:reference[not(. = $local:test)]
};
declare function local:test ($f) {
let $start := util:system-time()
let $run := $f()
let $duration := (util:system-time() - $start) div $local:millisecond
return "Found " || string-join($run, ", ") || " of " || $local:max || " in " || $duration || "ms"
};
(
"one:", local:test(local:one#0)
,
"two:", local:test(local:two#0)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment