1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/* The naive reverse benchmark */
nrev(ShowResult) :-
bench(2500, ShowResult).
nrev([],[]).
nrev([X|Rest],Ans):-
nrev(Rest,L),
append(L,[X],Ans).
my_append([],L,L).
my_append([X|L1],L2,[X|L3]):-
my_append(L1,L2,L3).
/* commented since it is defined in common.pl
get_cpu_time(T) :-
statistics(runtime,[T|_]).
*/
bench(Count, ShowResult):-
get_cpu_time(T0),
dodummy(Count),
get_cpu_time(T1),
dobench(Count),
get_cpu_time(T2),
( ShowResult = true ->
report(Count,T0,T1,T2)
; true).
dobench(Count):-
data(List),
repeat(Count),
nrev(List,_),
fail.
dobench(_).
dodummy(Count):-
data(List),
repeat(Count),
dummy(List,_),
fail.
dodummy(_).
dummy(_,_).
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).
report(Count,T0,T1,T2) :-
Time1 is T1-T0,
Time2 is T2-T1,
(Time2 =< Time1 ->
Time = 1
;
Time is Time2-Time1 /* Time spent on nreving lists */
),
Lips is (496*Count*1000)//Time,
write(Lips), write(' lips for '), write(Count),
write(' iterations taking '), write(Time),
write(' msec ('),
write(Time2-Time1), write(')'),
nl.
% benchmark interface
benchmark(ShowResult) :-
nrev(ShowResult).
:- include(common).
|