Skip to content

Instantly share code, notes, and snippets.

@reborg
Created May 10, 2017 13:52
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 reborg/df6fbc2327194d8cfa1d0368c592a5dc to your computer and use it in GitHub Desktop.
Save reborg/df6fbc2327194d8cfa1d0368c592a5dc to your computer and use it in GitHub Desktop.
A few experiments for fast remove random element from a vector/list.
(let [v [0 1 2 3 4 5 6 7]]
(quick-bench
(let [n (rand-int (count v))]
(doall (concat (take n v) (drop (inc n) v))))))
;; 804.634866 ns
(let [v [0 1 2 3 4 5 6 7]]
(quick-bench
(rest (shuffle v))))
;; 181.223551 ns
(let [v [0 1 2 3 4 5 6 7]]
(quick-bench
(pop (assoc v (rand-int (dec (count v))) (peek v)))))
;; 173.573571 ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment