I have a function foo:
(defn foo [a b] (* a b)) ; <- 2 ms per 10K
(foo 3 8) ; <- 24
I want to be able to pass it agents, atoms, or refs as well.
(defn bar [a b] (* @a @b)) ; <- 3.5 ms per 10K
But then what about mixing literals and agents?
(defn aref? [x] (isa? (class x) clojure.lang.ARef))
(defn foo [a b] (let [a (if (aref? a) @a a)
b (if (aref? b) @b b)]
(* a b))
(def x (ref 3))
(def y (ref 8))
(foo 3 8); <- 120 ms per 10K
(foo 3 y); <- 71 ms per 10K
(foo x 8); <- 73 ms per 10K
(foo x y); <- 6 ms per 10K
But those are some really funky running times. I tried changing the order of the branching in foo, and that apparently has nothing to do with it. Why does my new foo take 20 times longer to evaluate over literals than over ARefs?