Is there any way to do some benchmarking on several Prolog programs? I am using SWI-Prolog, and it doesn't show the time taken to execute the query!!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
What about time/1
? In SWI-Prolog, try:
?- time(your_goal).
and
?- profile(your_goal).
回答2:
ok , found something useful .. predicate call_with_time_limit
meta_predicate time:call_with_time_limit(+,0).
time:call_with_time_limit(A, C) :-
A>0, !,
setup_call_cleanup(alarm(A, time_limit_exceeded(A), B, [install(false)]), run_alarm_goal(B, C), remove_alarm_notrace(B)).
time:call_with_time_limit(_, _) :-
throw(time_limit_exceeded).
you can define the time limit for the query, execute that on different queries and compare the number of result back within that time period, it is not that efficient but thats what i have found so far
回答3:
In GNU-Prolog time predicate can be taken from Prolog Compatibility Layers.
Referring to David Reitter's GNU Prolog compatibility layer :
%time
time(Goal) :-
cpu_time(CPU),
Goal,
cpu_time(CPU2),
CPUT is CPU2-CPU,
write('time: '), write(CPUT), write('ms.\n').
time(Text, Goal) :-
cpu_time(CPU),
Goal,
cpu_time(CPU2),
CPUT is CPU2-CPU,
write(Text), write(': '), write(CPUT), write('ms.\n').