Created
June 23, 2016 01:12
-
-
Save nathanmarz/1dc9ea1ff219ca2f1fa25e7d6f5fbfd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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