| /* CHANGELOG by M.Banbara |
| - print_times/4 --> print_times/5 |
| - report_csv/2 is added. |
| */ |
| |
| /* The predicates are called: */ |
| |
| /* o "choice_point(N)" - creation of choice points */ |
| /* o "choice_point0ar(N) - same, with 0 arg */ |
| /* o "baktrak1(N)" - deep backtracking */ |
| /* o "baktrak2(N)" - shallow backtracking */ |
| |
| /* N is the number of loop iterations executed */ |
| |
| |
| /* predicate to test creation of choice points without backtracking */ |
| /* suggested value for N: 1000 */ |
| /* results for Cprolog N=1000 */ |
| /* Tloop=5.95 Tcompens=0.98 Tnet=4.97 Klips=4.02 */ |
| |
| choice_point(N):-statistics(runtime,[T1|_]), |
| cre_CP(N), statistics(runtime,[T2|_]), |
| compens_loop(N), statistics(runtime,[T3|_]), |
| print_times(choice_point(N),T1,T2,T3,N,20). |
| |
| /* predicate choice_point, but with zero argument */ |
| /* suggested value for N: 1000 */ |
| /* results for Cprolog: N=1000 */ |
| /* Tloop=3.55 Tcompens=0.98 Tnet=2.57 Klips=7.7 */ |
| |
| |
| choice_point0ar(N):-statistics(runtime,[T1|_]), |
| cre_CP0ar(N), statistics(runtime,[T2|_]), |
| compens_loop(N), statistics(runtime,[T3|_]), |
| print_times(choice_point0ar(N),T1,T2,T3,N,20). |
| /* Predicate to test the (deep) backtracking mechanism. */ |
| /* suggested value for N: 1000 (interp), 2000(comp) */ |
| /* results for Cprolog: N=1000 */ |
| /* Tloop=9.63 Tcomp=1 Tnet=8.63 Klips=2.32 */ |
| |
| baktrak1(N) |
| :- statistics(runtime,[T1|_]), |
| deep_back(N), |
| statistics(runtime,[T2|_]), |
| compens_loop(N), |
| statistics(runtime,[T3|_]), |
| print_times(baktrak1(N),T1,T2,T3,N,20). |
| |
| |
| /* Predicate to test the (shallow) backtracking mechanism */ |
| /* suggested value for N: 1000 (interp), 2000 (comp) */ |
| /* results for Cprolog: N=1000 */ |
| /* Tloop=3.63 Tcomp=0.95 Tnet=2.68 Klips=7.45 */ |
| |
| baktrak2(X) |
| :- statistics(runtime,[T1|_]), |
| shallow_back(X), statistics(runtime,[T2|_]), |
| compens_loop(X), statistics(runtime,[T3|_]), |
| print_times(baktrak2(X),T1,T2,T3,X,20). |
| |
| |
| /* compensation loop, used to measure the time spent in the loop */ |
| compens_loop(0). |
| compens_loop(X) :- Y is X - 1, compens_loop(Y). |
| |
| /* loop to test choice point creation */ |
| cre_CP(0). |
| cre_CP(N):-M is N-1, ccp1(0,0,0), cre_CP(M). |
| |
| cre_CP0ar(0). |
| cre_CP0ar(N):-M is N-1, ccp1, cre_CP0ar(M). |
| |
| /* loop to test deep backtracking */ |
| deep_back(0). |
| deep_back(X) :- pd(_,_,_), Y is X - 1, deep_back(Y). |
| |
| /* loop to test shallow backtracking */ |
| shallow_back(0). |
| shallow_back(X) :- ps(_,a,b), Y is X - 1, shallow_back(Y). |
| |
| |
| print_times(Name,T1,T2,T3,X,I) :- /* prints the results */ |
| TT1 is T2 - T1, |
| TT2 is T3 - T2, |
| TT is TT1 - TT2, |
| write('# Name: '),write(Name), nl, |
| write('# T overall loop: '),write(TT1), write(' msec.'),nl, |
| write('# T compens loop: '),write(TT2), write(' msec.'),nl, |
| write('# T net: '),write(TT),write(' msec.'),nl, |
| write('# KLips: '), |
| Li is I * X, |
| Lips is Li / TT, |
| KLips is Lips / 1000, |
| write(KLips),nl, |
| report_csv(['###CSV###',Name,TT1,TT2,TT,KLips], ','), |
| nl. |
| |
| report_csv([], _) :- !. |
| report_csv([X], _) :- !, write(X), nl. |
| report_csv([X|Xs], Delim) :- write(X), write(Delim), report_csv(Xs, Delim). |
| |
| |
| /* ccp1 creates 20 choice points */ |
| /* ccp1 is the beginning of a set of predicates */ |
| /* composed of 2 clauses each. Every invokation of nd0 will create */ |
| /* a sequence of 20 choice points. The body of the clauses are */ |
| /* limited to one goal, thus avoiding a creation of environment */ |
| /* when the clause is activated. nd0, and its successors, have */ |
| /* three arguments to comply with our average static analysis */ |
| /* results made on more than 30 real Prolog programs. */ |
| /* ccpXX exists with 3 argu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p6. |
| ccp5. |
| ccp6:-ccp7. |
| ccp6. |
| ccp7:-ccp8. |
| ccp7. |
| ccp8:-ccp9. |
| ccp8. |
| ccp9:-ccp10. |
| ccp9. |
| ccp10:-ccp11. |
| ccp10. |
| ccp11:-ccp12. |
| ccp11. |
| ccp12:-ccp13. |
| ccp12. |
| ccp13:-ccp14. |
| ccp13. |
| ccp14:-ccp15. |
| ccp14. |
| ccp15:-ccp16. |
| ccp15. |
| ccp16:-ccp17. |
| ccp16. |
| ccp17:-ccp18. |
| ccp17. |
| ccp18:-ccp19. |
| ccp18. |
| ccp19:-ccp20. |
| ccp19. |
| |
| ccp20. |
| ccp20. |
| |
| |
| /* deep backtracking */ |
| /* The call to pd creates a choice point, and invokes a */ |
| /* call to q. It will fail and there will be a backtracking */ |
| /* step to try the next clause defining pd. pd has 21 */ |
| /* clauses,thus failure */ |
| /* occurs 20 times */ |
| |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_) :- q(X1,X2,a). |
| pd(X1,X2,_). |
| |
| q(X1,X2,b). |
| |
| |
| /* shallow backtracking */ |
| /* The ps predicate fails 20 times. The shallow backtracking */ |
| /* will not restore all current state registers in Prolog */ |
| /* systems which perform this optimisation, while others will. */ |
| |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,X,X). |
| ps(_,_,_). |