%% 時間計測のプログラム
%% 使用法 test(繰返し回数,述語名(引数1,引数2,...)).

test(Times,Goal) :-
    Goal =.. [Pred|Args],
    statistics(runtime,[T0|_]),
    loopfunc(Times,Goal),
    statistics(runtime,[T1|_]),
    Time is T1-T0,
    length(Args,Arity),
    format('~a/~d took ~3d sec.~n',[Pred,Arity,Time]).

loopfunc(0,_) :-!.
loopfunc(X,Goal) :-
    copy_term(Goal,Copy),
    call(Copy),
    Y is X-1,
    loopfunc(Y,Goal).
