You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into a use case for a work product that needed to quickly test membership between 2 sets to
see if "any" member existed in both, and return the first intersecting member as fast as possible.
user> (let [s1 #{:a:b } s2 #{:g:a}] (c/quick-bench (slow-some-member s1 s2)))
Evaluation count : 975378 in 6 samples of 162563 calls.
Execution time mean : 612.287581ns
Execution time std-deviation : 3.310927ns
Execution time lower quantile : 608.261646ns ( 2.5%)
Execution time upper quantile : 615.629475ns (97.5%)
Overhead used : 2.233057nsnil
user> (let [s1 #{:a:b } s2 #{:g:a}] (c/quick-bench (some-member s1 s2)))
Evaluation count : 2004582 in 6 samples of 334097 calls.
Execution time mean : 300.056678ns
Execution time std-deviation : 2.946006ns
Execution time lower quantile : 297.321682ns ( 2.5%)
Execution time upper quantile : 303.695844ns (97.5%)
Overhead used : 2.233057nsnil
user> (let [s1 #{:a:b } s2 #{:g:a}] (c/quick-bench (some-member2 s1 s2)))
Evaluation count : 3298134 in 6 samples of 549689 calls.
Execution time mean : 181.087016ns
Execution time std-deviation : 0.816367ns
Execution time lower quantile : 180.408265ns ( 2.5%)
Execution time upper quantile : 182.115366ns (97.5%)
Overhead used : 2.233057nsnil
Gains are variable, and I haven't studied them for a wide range of set combinations. I'm interested in any faster means of doing this, although I just realized that my specific use case is amenable to memoization, which improves runtime (via memo-2) like 10x over my original "optimized" some-member.
user> (let [f (memo-2 some-member2) s1 #{:a:b } s2 #{:g:a}] (c/quick-bench (f s1 s2)))
Evaluation count : 19762416 in 6 samples of 3293736 calls.
Execution time mean : 28.191368ns
Execution time std-deviation : 0.181916ns
Execution time lower quantile : 28.035774ns ( 2.5%)
Execution time upper quantile : 28.427699ns (97.5%)
Overhead used : 2.233057ns
The text was updated successfully, but these errors were encountered:
I ran into a use case for a work product that needed to quickly test membership between 2 sets to
see if "any" member existed in both, and return the first intersecting member as fast as possible.
A naive way one might reach for is
Original implementation was
Which of course has some inefficiencies due to destructuring and slow function calls through clojure.lang.RT.
Revised version assumes sets as input,
Gains are variable, and I haven't studied them for a wide range of set combinations. I'm interested in any faster means of doing this, although I just realized that my specific use case is amenable to memoization, which improves runtime (via memo-2) like 10x over my original "optimized"
some-member
.The text was updated successfully, but these errors were encountered: