Created
April 18, 2021 14:08
-
-
Save saikyun/f71991b050ed1e55de77b1adde9e3568 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 timeit2 | |
``` | |
Time the execution of `form` using `os/clock` before and after, | |
and print the result to stdout. returns: result of executing `form`. | |
Uses `tag` (default "Elapsed time:") to tag the printout. | |
``` | |
[form &opt tag] | |
(default tag "Elapsed time:") | |
(with-syms [start result end] | |
~(do | |
(def ,start (os/clock)) | |
(def ,result ,form) | |
(def ,end (os/clock)) | |
(- ,end ,start)))) | |
(def wat (fiber/new (fn [] (while true (yield 1))))) | |
(def wat2 (fn [] 1)) | |
(do | |
(var res 0) | |
(loop [i :range [0 100000]] | |
(+= res (timeit2 (resume wat)))) | |
res) | |
#=> 0.277963 | |
(do | |
(var res 0) | |
(loop [i :range [0 100000]] | |
(+= res (timeit2 (wat2)))) | |
res) | |
#=> 0.276217 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment