Skip to content

Instantly share code, notes, and snippets.

@saikyun
Created April 18, 2021 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saikyun/f71991b050ed1e55de77b1adde9e3568 to your computer and use it in GitHub Desktop.
Save saikyun/f71991b050ed1e55de77b1adde9e3568 to your computer and use it in GitHub Desktop.
(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