2011-01-03 11 views

Antwort

8

Was ist mit time/1? In SWI-Prolog, versuchen:

?- time(your_goal). 

und

?- profile(your_goal). 
1

ok, fand etwas nützlich .. Prädikat 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). 

Sie die Frist für die Abfrage definieren können, führen, dass auf verschiedene Abfragen und die Anzahl des Ergebnisses vergleichen zurück innerhalb dieser Zeitspanne ist es nicht so effizient, aber das ist, was ich bisher gefunden habe

1

in GNU-Prolog Zeit Prädikat aus Prolog Compatibility Layers genommen werden.

Mit Bezug auf 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'). 
Verwandte Themen