(def v1 (for [x (range 10000000)] (rand-int 10000000))) (count v1) (require '[clojure.core.reducers])
(defn x-in-coll? [x coll] (clojure.core.reducers/reduce (fn [res next-v] (if (= next-v x) (reduced true) false)) false coll)) (defn x-in-coll2? [x coll] (some #(= x %) coll)) (time (x-in-coll? 0 v1)) (time (x-in-coll2? 0 v1))
(time (x-in-coll? 0 v1)) "Elapsed time: 176.250871 msecs" => false (time (x-in-coll2? 0 v1)) "Elapsed time: 559.220763 msecs" => nil
Комментариев нет:
Отправить комментарий