Created
October 17, 2021 06:18
-
-
Save danownsthisspace/5c41c9aa17fa57e2ce1528405dd85db9 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
(ns otca.shorts) | |
(defn wait-return [s r] | |
(Thread/sleep (* s 1000)) | |
r) | |
#_(defn time-taken [expr] | |
(let [start (. System (nanoTime)) | |
result (expr) | |
end (. System (nanoTime)) | |
total-time (/ (double (- end start)) 100000.0)] | |
(println "Took " total-time " to eval") | |
result)) | |
(defmacro time-taken [& expr] | |
`(let [start# (. System (nanoTime)) | |
result# (do | |
~@expr) | |
end# (. System (nanoTime)) | |
total-time# (/ (double (- end# start#)) 100000.0)] | |
(println '~expr " took " total-time# " to eval") | |
result#)) | |
(comment | |
(def var1 "one") | |
`(list ~var1 2 3) | |
(wait-return 2 "hey") | |
(time-taken (+ 1 1)) | |
(time-taken (+ 1 1) (wait-return 2 "hey")) | |
(macroexpand-1 '(time-taken (+ 1 1) (wait-return 2 "hey")))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for linking to this code though.