Running time in Ocaml

后端 未结 3 1526
挽巷
挽巷 2020-12-11 01:46

How to figure out the amount of time my code has taken in ocaml? are there any functions to measure that?

3条回答
  •  攒了一身酷
    2020-12-11 02:26

    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
    

    where f is any function which takes x as the argument and returns something.

提交回复
热议问题