Fork me on GitHub
#clojure-uk
<
2019-09-04
>
rickmoynihan08:09:20

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)]
     [email protected]
     (let [end# (System/currentTimeMillis)
           form-str# ~(if (>= (count forms) 2)
                        `(pr-str '(do [email protected]))
                        `(pr-str '[email protected]))]
       (println "Time taken for" form-str# "was" (- end# start#) "ms"))))
But wondering if there’s something similar in a library.

rickmoynihan08:09:32

Also I’ve seen http://github.com/ptaoussanis/tufte but it’s not really appealing to me…

rickmoynihan08:09:29

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.

peterwestmacott07:09:02

there's a time function in core iirc.

peterwestmacott07: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.

rickmoynihan07:09:18

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

otfrom08:09:31

@rickmoynihan sounds like a job for tap>?

otfrom08:09:45

which these other libs won't have done before

rickmoynihan08:09:26

ahh yes good point

rickmoynihan08:09:40

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

otfrom12:09:13

everything is just println in disguise kylorenmask

alexlynham13:09:36

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

otfrom13:09:02

I do what I can. 😉

Conor13:09:40

You missed the rest of it @alex.lynham