Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I measure the CPU time a Clojure function takes to execute?

Tags:

clojure

I have seen profiling macros for Clojure but they all seem to use elapsed time. Is there any way to get the CPU time taken?

like image 699
yazz.com Avatar asked Apr 05 '11 09:04

yazz.com


1 Answers

Not seen such a solution.

However, you can probably achieve it with the java.lang.management Java package which supports management / monitoring of the JVM.

In particular, the ThreadMXBean.getCurrentThreadCPUTime() sounds like it would do what you want.

Normally however I would just try and run my benchmark in an uncontested environment (i.e. one where it can get 100% CPU) and make the simplyfying assumption that elapsed time is approximately equal to CPU time. Then you can use the usual Clojure benchmarking tools, e.g. Criterium.

like image 67
mikera Avatar answered Sep 20 '22 18:09

mikera