Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created May 20, 2011 18:02
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 swannodette/983429 to your computer and use it in GitHub Desktop.
Save swannodette/983429 to your computer and use it in GitHub Desktop.
ifn.clj
(defrecord A [a b c]
clojure.lang.IFn
(invoke [this k]
(cond
(identical? k :a) a
(identical? k :b) b
(identical? k :c) c
:else nil)))
(comment
;; ~70ms
(dotimes [_ 10]
(let [x (A. 1 2 3)]
(time
(dotimes [_ 1e8]
(x :c)))))
;; ~70ms
(dotimes [_ 10]
(let [x (A. 1 2 3)]
(time
(dotimes [_ 1e8]
(.c ^A x)))))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment