/* The naive reverse benchmark */ option(guard_simplification,on). option(mode,nrev(+,?)). option(mode,app(+,+,?)). option(type_definition,type(list(X), [ [], [X | list(X) ]])). option(type_declaration,nrev(list(int),list(int))). option(type_declaration,app(list(int),list(int),list(int))). go :- go(50000). :- constraints nrev/2, app/3. nrev([],R) <=> R = []. nrev([X|Rest],Ans) <=> nrev(Rest,L), app(L,[X],Ans). app([],L,Ans) <=> Ans = L. app([X|L1],L2,Ans) <=> Ans = [X|L3],app(L1,L2,L3). nrev2([],[]). nrev2([X|Rest],Ans):- nrev2(Rest,L), app2(L,[X],Ans). app2([],L,L). app2([X|L1],L2,[X|L3]):- app2(L1,L2,L3). go(Count):- measure(dobench(Count), true, Utime,Gtime,System), write(bench(nrev_CHR,Count,Utime,Gtime,System)), write('.'),nl,fail. go(Count):- measure(dobench2(Count), true, Utime,Gtime,System), write(bench(nrev_prolog,Count,Utime,Gtime,System)), write('.'),nl,fail. go(_). dobench(Count):- data(List), repeat(Count), nrev(List,_), fail. dobench(_). dobench2(Count):- data(List), repeat(Count), nrev2(List,_), fail. dobench2(_). data(X):- data(X,30). data([],0). data([a|Y],N):- N > 0, N1 is N-1, data(Y,N1). repeat(_N). repeat(N):- N > 1, N1 is N-1, repeat(N1).