문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top