Created
May 10, 2017 13:52
-
-
Save reborg/df6fbc2327194d8cfa1d0368c592a5dc to your computer and use it in GitHub Desktop.
A few experiments for fast remove random element from a vector/list.
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
(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