小编Ans*_*ter的帖子

显示谓词子句的每个目标的执行时间

我想在SICStus Prolog中看到谓词目标内的执行时间.

示例:

pred :-
   goal1,
   time,
   goal2,
   time.

go :-
   call(pred).

time_go :-
   go,
   times(go).
Run Code Online (Sandbox Code Playgroud)

预期结果:

?- time_go.
times_go = 1000ms ,   
times_go_goal1 = 500ms,
times_go_goal2 = 500ms
Run Code Online (Sandbox Code Playgroud)

怎么做 ?

我尝试过time_out(:Goal, +Time, -Result),library(timeout)但是我收到了这个错误:

| ?- time_out(char_code(a,N), T, Res).
! Instantiation error in argument 2 of user:time_out/3
! goal:  time_out(user:char_code(a,_193),_179,_181)

| ?- time_out(char_code(a,N), 1000, Res).
N = 97,
Res = success ? ; % Res=timeout in other example
Run Code Online (Sandbox Code Playgroud)

prolog

3
推荐指数
2
解决办法
1528
查看次数

标签 统计

prolog ×1