Search code examples
prologswi-prologsystemtime

calculating an algorithm time in prolog


I am solving Bridge and Torch puzzle by PROLOG. As I am trying different search methods, I need to find the calculation time. I mean the start time and the end time of solving the problem by the algorithm.

Can I have access to System time from Prolog ? How?


Solution

  • I calculated overall Time in a predicate using get_time(T) as this:

    print_solution :- 
      **get_time(T1),**
      init(State), 
      solve(State,Solution,EndState), 
      writeln('Start state:'),
      writeln(State),
      writeln('Solution:'),
      writeln(Solution),
      writeln('Final state:'),
      writeln(EndState),
      **get_time(T2),**
      **DeltaT is T2- T1,**
      **write('time: '), write(DeltaT), write('  ms.\n'), nl.**