Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn foo [a b] (* a b)) ; <- 2 ms per 10K
- (foo 3 8) ; <- 24
- (defn bar [a b] (* @a @b)) ; <- 3.5 ms per 10K
- (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
- (defn aref? [x]
- (instance? clojure.lang.ARef x))
- (defn foo [a b] (let [a (if (aref? a) @a a)
- b (if (aref? b) @b b)]
- (* a b)))
- (def a (ref 3))
- (def b (ref 8))
- (time (dotimes [i 10000] (foo a b))) ; ~ 9ms
- (time (dotimes [i 10000] (foo a 8))) ; ~ 2.7ms
- (time (dotimes [i 10000] (foo 3 b))) ; ~ 2.7ms
- (time (dotimes [i 10000] (foo 3 8))) ; ~ 1.7ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement