AhmadAssaf
AhmadAssaf

Reputation: 3654

How to test the performance of a Prolog program?

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!!

Upvotes: 3

Views: 4048

Answers (3)

mat
mat

Reputation: 40768

What about time/1? In SWI-Prolog, try:

?- time(your_goal).

and

?- profile(your_goal).

Upvotes: 8

Grzegorz Wierzowiecki
Grzegorz Wierzowiecki

Reputation: 10843

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').

Upvotes: 1

AhmadAssaf
AhmadAssaf

Reputation: 3654

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

Upvotes: 1

Related Questions