% a script for benchmarking, by Neng-Fa Zhou go:- open(res_bp,write,S), run(S). compall:- programs(Ps), '$member'((P,N),Ps), compile(P), fail. compall. run(S):- programs(Ps), '$member'((P,N),Ps), run_program(P,N,S), fail. run(S):-close(S). run_program(P,N,S):- % compile(P), load(P), % consult(P), ntimes(N,T),!, write(S,P),write(S,'('), T1 is T/N, write(S,T1), write(S,').'),nl(S). ntimes(N,T):- statistics(runtime,_), ntimes(N), statistics(runtime,[_,T1]), ntimes_dummy(N), statistics(runtime,[_,T2]), T is T1-T2. ntimes(N):-N=:=0,!. ntimes(N):-not_not_top, !, N1 is N-1,ntimes(N1). ntimes_dummy(N):-N=:=0,!. ntimes_dummy(N):-not_not_dummy, !, N1 is N-1,ntimes_dummy(N1). not_not_top:-not_top,!,fail. not_not_top. not_top:-top,!,fail. not_top. not_not_dummy:-not_dummy,!,fail. not_not_dummy. not_dummy:-dummy,!,fail. not_dummy. dummy. ratios(F1,F2):- readall(F1,L1,_), readall(F2,L2,_), length(L1,N), ratios(L1,L2,Ratios), sum(Ratios,0,Sum), prod(Ratios,1,Prod), output_ratios(Ratios), Amean is Sum/N, Gmean is exp(1/N*log(Prod)), write_ln(user_output,['', Amean],' & ',' \\hline \\\\'), write_ln(user_output,['', Gmean],' & ',' \\hline \\\\'). readall(F,L,N):- see(F), read(X), functor(X,_,N), read_data(X,L). read_data(end_of_file,L):-!,L=[],seen. read_data(X,L):- L=[X|L1], read(NewX), read_data(NewX,L1). ratios([],[],[]). ratios([P1|L1],[P2|L2],[P3|L3]):- P1=..[Name,Time1|_], P2=..[Name,Time2|_], Ratio is Time1/Time2, P3=..[Name,Ratio], ratios(L1,L2,L3). sum([P|L],Sum0,Sum):- P=..[Name,R], Sum1 is Sum0+R, sum(L,Sum1,Sum). sum([],Sum,Sum). prod([P|L],Prod0,Prod):- P=..[Name,R], Prod1 is Prod0*R, prod(L,Prod1,Prod). prod([],Prod,Prod). output_ratios([]). output_ratios([Ratio|Ratios]):- Ratio=..[Name,R], write_ln(user_output,[Name,R],' & ',' \\hline \\\\'), output_ratios(Ratios). '$member'(X,[X1|Xs]):- X=X1. '$member'(X,[X1|Xs]):- '$member'(X,Xs). write_ln(S,[],Dem,End):- write(S,End),nl(S). write_ln(S,[X],Dem,End):-!,write_item(S,X),write(S,End),nl(S). write_ln(S,[X|Xs],Dem,End):-write_item(S,X),write(S,Dem), write_ln(S,Xs,Dem,End). write_item(S,X):-atom(X),!,atom_length(X,N), Tab is 20-N, write(S,X),spaces(S,Tab). write_item(S,X):-Y is truncate(X*100)/100, write(S,Y). spaces(S,Tab):-Tab>0,!,write(S,' '),Tab1 is Tab-1,spaces(S,Tab1). spaces(S,Tab). initialize_structure(Sum,N0,N,Value):- N0=