Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(defn fast-constantly [v]
(fn ([] v)
([a1] v)
([a1 a2] v)
([a1 a2 a3] v)
([a1 a2 a3 a4] v)
([a1 a2 a3 a4 a5] v)
([a1 a2 a3 a4 a5 a6] v)
([a1 a2 a3 a4 a5 a6 a7] v)
([a1 a2 a3 a4 a5 a6 a7 a8] v)
([a1 a2 a3 a4 a5 a6 a7 a8 a9] v)
([a1 a2 a3 a4 a5 a6 a7 a8 a9 a10] v)
([a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 & r] v)
))
(def f1 (constantly 2))
(def f2 (fast-constantly 2))
user=> (benchmark 100000000 #(f1 1 2 3))
"Elapsed time: 1813.155 msecs"
user=> (benchmark 100000000 #(f2 1 2 3))
"Elapsed time: 600.159 msecs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.