Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. (defn foo [a b] (* a b)) ; <- 2 ms per 10K
  2. (foo 3 8) ; <- 24
  3.  
  4. (defn bar [a b] (* @a @b)) ; <- 3.5 ms per 10K
  5.  
  6. (defn aref? [x] (isa? (class x) clojure.lang.ARef))
  7. (defn foo [a b] (let [a (if (aref? a) @a a)
  8. b (if (aref? b) @b b)]
  9. (* a b))
  10. (def x (ref 3))
  11. (def y (ref 8))
  12. (foo 3 8); <- 120 ms per 10K
  13. (foo 3 y); <- 71 ms per 10K
  14. (foo x 8); <- 73 ms per 10K
  15. (foo x y); <- 6 ms per 10K
  16.  
  17. (defn aref? [x]
  18. (instance? clojure.lang.ARef x))
  19.  
  20. (defn foo [a b] (let [a (if (aref? a) @a a)
  21. b (if (aref? b) @b b)]
  22. (* a b)))
  23. (def a (ref 3))
  24. (def b (ref 8))
  25. (time (dotimes [i 10000] (foo a b))) ; ~ 9ms
  26. (time (dotimes [i 10000] (foo a 8))) ; ~ 2.7ms
  27. (time (dotimes [i 10000] (foo 3 b))) ; ~ 2.7ms
  28. (time (dotimes [i 10000] (foo 3 8))) ; ~ 1.7ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement