本文介绍了Ocaml的运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何计算我的代码在ocaml中花费的时间?有什么功能可以衡量吗?
How to figure out the amount of time my code has taken in ocaml? are there any functions to measure that?
推荐答案
如果要测量各个函数的执行时间,此实用程序函数在许多情况下会很有帮助:
If you want to measure execution time of individual functions, this utility function is helpful in many cases:
let time f x =
let t = Sys.time() in
let fx = f x in
Printf.printf "Execution time: %fs\n" (Sys.time() -. t);
fx
其中f
是任何以x
作为参数并返回内容的函数.
where f
is any function which takes x
as the argument and returns something.
这篇关于Ocaml的运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!