开发者

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

开发者 https://www.devze.com 2023-02-22 07:09 出处:网络
开发者_C百科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?Not seen such a solution.
开发者_C百科

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消