I need to calculate the execution time of pro log program, because I searching in 4500 rules in a knowledge base. I found the following source code but I don’t know , what can set the input parameters for example TimeSinceStart parameter.
If you just want to see the execution time for debugging, you can use SWI-Prolog’s built-in time/1 predicate:
?- time(some_slow_code).
% 7,940,026 inferences, 1.144 CPU in 1.152 seconds (99% CPU, 6939812 Lips)
true.
(The “1.152 seconds” is the walltime value that you’re looking for.)
But time/1 only prints the time statistics and doesn’t return them. If you want to store or accumulate the times, you need to use statistics/2 directly.
To clarify, statistics/2 doesn’t take any inputs - both entries in the list are output values. TimeSinceStart is the walltime since the Prolog process was started, and TimeSinceLastCall is the time since the last statistics(walltime, ...) call (both in milliseconds). It’s easiest to understand if you try it out interactively:
In this example, the first statistics/2 call was 1.3 seconds after Prolog was started, and the second one was 3.0 seconds after Prolog was started and 1.7 seconds after the first call.
That’s how I understood that must use statistics/2 predicate before the first statement : Statistics(wall time, stats) and last statement of pro log program Statistics(wall time, stats) and then subtract two values of stats variable.
Dear Peter,
Many Thanks for your consideration and beneficence, If the CPUTime is total execution time of my program, your SWI-Prolog code is proper for me.