How to test the performance of a Prolog program?

前端 未结 3 2055
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-06 14:23

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

相关标签:
3条回答
  • 2021-01-06 14:54

    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').
    
    0 讨论(0)
  • 2021-01-06 14:55

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

    ?- time(your_goal).
    

    and

    ?- profile(your_goal).
    
    0 讨论(0)
  • 2021-01-06 15:16

    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

    0 讨论(0)
提交回复
热议问题