I’m stumbling across a strange (to me) performance issue, trying to convert a BitSet to a vector using this approach:
(defn bitset->vec [bits] (->> bits .size range (filter (fn [x] (.get bits x))) (into ))) (comment (def bits (java.util.BitSet.)) (.set bits 0 499999) (time (count (bitset->vec bits)))) "Elapsed time: 3258.975805 msecs"
Why does that takes such a long time?
Here is a faster way of doing it:
(defn bitset->vec2 [bits] (as-> (.toString bits) v ((fn [s] (subs s 1 (dec (count s)))) v) (string/split v #", ") (mapv #(Integer/parseInt %) v))) (comment (time (count (bitset->vec2 bits)))) "Elapsed time: 180.76525 msecs"
But it feels a bit insane to have to resort to that…
How would you do it?