home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / b / binprolog / !BinPro330 / progs / bmark < prev    next >
Encoding:
Text File  |  1994-10-16  |  1011 b   |  47 lines

  1. timer(T):-statistics(runtime,[T,_]).
  2.  
  3. test_times(It,Goal):- range(_,1,It),Goal,fail.
  4. test_times(_,_).
  5.  
  6. dummy.
  7. dummy(_).
  8. dummy(_,_).
  9. dummy(_,_,_).
  10. dummy(_,_,_,_).
  11. dummy(_,_,_,_,_).
  12.  
  13. make_dummy(Goal,Dummy):-Goal=..[_|Xs],Dummy=..[dummy|Xs].
  14.  
  15. range(Min,Min,Max):-Min=<Max.
  16. range(I,Min,Max):-
  17.         Min<Max,
  18.         Min1 is Min+1,
  19.         range(I,Min1,Max).
  20.  
  21. bmark(It,Goal,Time):-
  22.     make_dummy(Goal,Dummy),
  23.     timer(T0),
  24.     test_times(It,Dummy),
  25.     timer(T1),
  26.     test_times(It,Goal),
  27.     timer(T2),
  28.     Time is (T2-T1)-(T1-T0).
  29.  
  30.  
  31. rusage(Goal,H,Tr,S):-
  32.         statistics(global_stack,[H1,_]),
  33.         statistics(trail,[T1,_]),
  34.         statistics(local_stack,[S1,_]),
  35.         Goal,
  36.         statistics(global_stack,[H2,_]),
  37.         statistics(trail,[T2,_]),
  38.         statistics(local_stack,[S2,_]),
  39.         H is H2-H1,Tr is T2-T1,S is S2-S1.
  40.  
  41. go(Mes,It,Goal):-
  42.     bmark(It,Goal,Time),
  43.     functor(Goal,F,N),
  44.         nl,write(Mes=[goal=F/N,iterations=It,time=Time]),nl,
  45.     rusage(Goal,H,Tr,S),
  46.     nl,write(Mes=[heap=H,trail=Tr,stack=S]),nl.
  47.