Fork me on GitHub

Does anyone know of any small libraries suitable for performance testing / instrumenting small blocks of code with timing measurements? Obviously I know of criterium, which I use already — but I’m not interested in microbenchmarking, more just getting a feel for how long remote calls are taking… e.g. http requests, database queries, and perhaps occaisional blocks of code; where performance can be measured in seconds or minutes. I normally write a macro like this for the job:

(defmacro timeit [& forms]
  `(let [start# (System/currentTimeMillis)]
     (let [end# (System/currentTimeMillis)
           form-str# ~(if (>= (count forms) 2)
                        `(pr-str '(do ~@forms))
                        `(pr-str '~@forms))]
       (println "Time taken for" form-str# "was" (- end# start#) "ms"))))
But wondering if there’s something similar in a library.


Also I’ve seen but it’s not really appealing to me…


I think it’d be nice to have something like the above, and perhaps a variant that will re define a var holding a function for you… but surely many people have packaged this up into a library.

Rachel Westmacott07:09:02

there's a time function in core iirc.

Rachel Westmacott07:09:30

I'm expecting that as more people move to tools.deps/deps.edn (with the ability to pull arbitrary code from github), that micro/nano libraries will become more common.


yeah I use the time macro a lot; but it has no means of identifying which output is from which call site.


@rickmoynihan sounds like a job for tap>?


which these other libs won't have done before


ahh yes good point


Though doesn’t that just mean replacing the println above with a call to tap>? I still need to write the macro — again! 🙂


everything is just println in disguise kylorenmask


that was quite wintlike @otfrom > the wise man bowed his head solemnly and spoke: "theres actually zero difference between println & other programs. "


I do what I can. 😉


You missed the rest of it @alex.lynham