Skip to content

Instantly share code, notes, and snippets.

@mbakhterev
Created April 27, 2017 18:53
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 mbakhterev/c8954f34526c990d4249b6448824347e to your computer and use it in GitHub Desktop.
Save mbakhterev/c8954f34526c990d4249b6448824347e to your computer and use it in GitHub Desktop.
(defrecord Test [^long a ^long b ^long c])
(defn- test-1 [] (->Test (rand-int 1000) (rand-int 1000) (rand-int 1000)))
(defn- redx-1 [S ^Test {a :a b :b c :c}] (+ S (* a b) c (* a c)))
(defn- redx-1-2 [S {a :a b :b c :c}] (+ S (* a b) c (* a c)))
(defn- test-2 [] {:a (rand-int 1000) :b (rand-int 1000) :c (rand-int 1000)})
(defn- redx-2 [S {a :a b :b c :c}] (+ S (* a b) c (* a c)))
(defn- test-3 [] (hash-map :a (rand-int 1000) :b (rand-int 1000) :c (rand-int 1000)))
(defn- redx-3 [S {a :a b :b c :c}] (+ S (* a b) c (* a c)))
(defn- test-4 [] (vector (rand-int 1000) (rand-int 1000) (rand-int 1000)))
(defn- redx-4 [S [a b c]] (+ S (* a b) c (* a c)))
(defn- test-5 [] [(rand-int 1000) (rand-int 1000) (rand-int 1000)])
(defn- redx-5 [S [a b c]] (+ S (* a b) c (* a c)))
(def ^:private ^:const N 1e+7)
(defrecord Test-2 [a b c])
(defn- test-6 [] (->Test-2 (rand-int 1000) (rand-int 1000) (rand-int 1000)))
(defn- redx-6 [S ^Test-2 {a :a b :b c :c}] (+ S (* a b) c (* a c)))
(defn- redx-6-1 [S {a :a b :b c :c}] (+ S (* a b) c (* a c)))
(doseq [[r t] (list [redx-1 test-1]
[redx-2 test-2]
[redx-3 test-3]
[redx-4 test-4]
[redx-5 test-5]
[redx-6 test-6]
[redx-6-1 test-6])]
(time (reduce r 0 (repeatedly N t))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment