Display the execution times for each goal of a predicate clause

前端 未结 3 492
遇见更好的自我
遇见更好的自我 2021-01-13 04:21

I want to see the execution time inside goals of predicate with SICStus Prolog.

Example :

pred :-
   goal1,
   time         


        
3条回答
  •  执念已碎
    2021-01-13 04:22

    You can use statistics/2 for that:

    statistics(runtime,[Start|_]),
    do_something,
    statistics(runtime,[Stop|_]),
    Runtime is Stop - Start.
    

    Alternatively, you can use total_runtime instead of runtime if you want to include time for garbage collection. Start and Stop are measured in milliseconds, but the last time I used it with SICStus it returned only multiple of 10. In a project we used calls to a custom external C library to retrieve a finer resolution.

    A remark to time_out/3: It is used to limit the runtime of a goal, not to measure its runtime. If the goal finishes in time, the result is success, if it needs more time the execution is aborted (internally a timeout exception is thrown) and the result is timeout.

提交回复
热议问题