Created
February 24, 2021 13:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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