Question

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?

Was it helpful?

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.** 

OTHER TIPS

Using get_time/1 for assessing the execution time of algorithms does not calculate the execution time of the algorithm in isolation, but of your entire computer's process stack. E.g., if your OS decides to run some process in the background, this can already change the time delta considerably.

SWI-Prolog has dedicated support for tracking the time spend on calculating all called predicates. For this you need to (1) import library statistics and (2) enclose the predicate you want to profile in profile/1.

For example:

:- use_module(library(statistics)).

run_test:-
  profile(my_predicate(MyArgument)).

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top