Created
June 8, 2015 09:01
-
-
Save adamneilson/76a0366010b93d55f5a9 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
λ: (time (+ 2 2)) | |
"Elapsed time: 0.02675 msecs" | |
4 |
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
λ: (timed (+ 2 2)) | |
"Timed +: 0.066662 msecs" | |
4 |
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
λ: (source time) | |
(defmacro time | |
"Evaluates expr and prints the time it took. Returns the value of | |
expr." | |
{:added "1.0"} | |
[expr] | |
`(let [start# (. System (nanoTime)) | |
ret# ~expr] | |
(prn (str "Elapsed time: " (/ (double (- (. System (nanoTime)) start#)) 1000000.0) " msecs")) | |
ret#)) | |
nil |
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
(defmacro get-funtion-name | |
[expr] | |
(prn (:name (meta (resolve expr))))) |
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
λ: (get-funtion-name +) | |
+ | |
nil |
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
λ: (get-funtion-name (+ 2 2)) | |
λ: ClassCastException clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol clojure.core/ns-resolve |
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
(defmacro better-get-funtion-name | |
[expr] | |
(let [sym (= (type expr) clojure.lang.Symbol)] | |
(prn (:name (meta (if sym | |
(resolve expr) | |
(resolve (first expr)))))))) |
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
λ: (better-get-funtion-name +) | |
+ | |
nil |
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
λ: (better-get-funtion-name (+ 2 2)) | |
+ | |
nil |
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
(defmacro timed [expr] | |
(let [sym (= (type expr) clojure.lang.Symbol)] | |
`(let [start# (. System (nanoTime)) | |
return# ~expr | |
res# (if ~sym | |
(resolve '~expr) | |
(resolve (first '~expr)))] | |
(prn (str "Timed " | |
(:name (meta res#)) | |
": " (/ (double (- (. System (nanoTime)) start#)) 1000000.0) " msecs")) | |
return#))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment