Display the execution times for each goal of a predicate clause

前端 未结 3 507
遇见更好的自我
遇见更好的自我 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:48

    I'd like to add two thoughts:

    1. Prolog allows for backtracking, so goals may succeed more than once.

      What's the "runtime" you are interested in?

      • Only the work for computing the previous answer?
      • Or rather the total time?
    2. Use statistics/2, but don't do it directly. Instead, use an abstraction like call_time/2.

    Sample query:

    ?- call_time((permutation([a,b,c,d,e,f,g,h,i],Xs),Xs=[_,_,g,f,e,d,c,b,a]), T_ms).
       Xs = [h, i, g, f, e, d, c, b, a], T_ms = 304
    ;  Xs = [i, h, g, f, e, d, c, b, a], T_ms = 345
    ;  false.
    

    Notice that call_time/2 succeeds twice and T_ms measures total runtime up to this point.

提交回复
热议问题