How to measure execution time in SWI-Prolog
If you plan on doing some heavy computation in Prolog you probably want to log how much time gets spent on a predicate.
To do so, you can rely on the statistics
predicate in conjunction with the walltime
atom parameter.
?- statistics(walltime, [TimeSinceStart | [TimeSinceLastCall]]),
some_heavy_operation,
statistics(walltime, [NewTimeSinceStart | [ExecutionTime]]),
write('Execution took '), write(ExecutionTime), write(' ms.'), nl.
statistics(walltime, Result)
sets Result
as a list, with the head being the total time since the Prolog instance was started, and the tail being a single-element list representing the time since the last statistics(walltime, _)
call was made.
Reference: statistics/2
Written by Francesco Pontillo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Prolog
Authors
frapontillo
8.444K
alexanderbrevig
2.932K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#