Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created December 26, 2011 22:15
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 amalloy/1522199 to your computer and use it in GitHub Desktop.
Save amalloy/1522199 to your computer and use it in GitHub Desktop.
repl-1=> (defprotocol GetX (get-x [this]))
GetX
repl-1=> (defrecord Foo [x]
repl-1=* GetX (get-x [this] x))
repl-1.Foo
repl-1=> (def foo (Foo. 10))
#'repl-1/foo
repl-1=> (time (dotimes [_ 1e7] (.x ^Foo foo)))
"Elapsed time: 71.083148 msecs"
nil
repl-1=> (time (dotimes [_ 1e7] (get-x foo)))
"Elapsed time: 205.333696 msecs"
nil
repl-1=> (time (dotimes [_ 1e7] (get-x ^Foo foo)))
"Elapsed time: 208.352809 msecs"
nil
repl-1=> (time (dotimes [_ 1e7] (:x ^Foo foo)))
"Elapsed time: 346.152969 msecs"
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment