meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
2021-04-30T22:32:36.186700Z

what is the fastest way to scan a collection? there is something faster than a m/scan?

(require '[taoensso.encore :as enc])
(require '[meander.epsilon :as m])

(def data (vec (repeatedly 1000000 (fn [] {:a (* (rand-int 100) (if (enc/chance 0.5) 1 -1))
                                           :b (* (rand-int 100) (if (enc/chance 0.5) 1 -1))
                                           :c (* (rand-int 100) (if (enc/chance 0.5) 1 -1))}))))

(enc/qb 1

  (doall
   (m/search data
     (m/scan {:a 1 :b 1 :c 1 :as ?m}) ?m))
  
  (->> data
       (filterv
        (fn [m]
          (m/find m
            {:a 1 :b 1 :c 1 :as ?m} ?m)))))
;; => [127.33 60.28] - in ms

noprompt 2021-04-30T22:40:35.188100Z

How fast is

(m/find data [(m/or {:a 1 :b 1 :c 1 :as !m} _) ...] !m)

2021-04-30T23:02:18.188800Z

(enc/qb 1
  (doall
   (m/search data
     (m/scan {:a 1 :b 1 :c 1 :as ?m}) ?m))
  
  (m/find data [(m/or {:a 1 :b 1 :c 1 :as !m} _) ...] !m)
  
  (->> data
       (filterv
        (fn [m]
          (m/find m
            {:a 1 :b 1 :c 1 :as ?m} ?m)))))
;; => [125.22 85.2 55.35]

2021-04-30T23:02:41.189100Z

is definitely faster

noprompt 2021-04-30T23:15:53.190300Z

The first two are going to have some overhead at the moment.

noprompt 2021-04-30T23:19:37.191500Z

You could always make a macro that uses filter and find together the way you have them.