How to test the performance of a Prolog program?

前端 未结 3 2057
佛祖请我去吃肉
佛祖请我去吃肉 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').
    

提交回复
热议问题