cc4531cd1e
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@53 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
51 lines
913 B
Plaintext
51 lines
913 B
Plaintext
|
|
:- object(timer).
|
|
|
|
|
|
:- info([
|
|
version is 1.0,
|
|
authors is 'Paulo Moura',
|
|
date is 1998/3/23,
|
|
comment is 'Call executing time profiler.']).
|
|
|
|
|
|
:- uses(time).
|
|
:- uses(loop).
|
|
|
|
|
|
:- public(timer/2).
|
|
:- metapredicate(timer(::, *)).
|
|
|
|
:- mode(timer(+callable, -number), one).
|
|
|
|
:- info(timer/2,
|
|
[comment is 'Returns time to execute a call.',
|
|
argnames is ['Call', 'Time']]).
|
|
|
|
|
|
:- public(timer/3).
|
|
:- metapredicate(timer(::, *, *)).
|
|
|
|
:- mode(timer(+callable, +integer, -float), one).
|
|
|
|
:- info(timer/3,
|
|
[comment is 'Returns the average time needed to to execute a call.',
|
|
argnames is ['Call', 'Times', 'Time']]).
|
|
|
|
|
|
timer(Call, Time) :-
|
|
time::cpu_time(Start),
|
|
(call(Call) -> true; true),
|
|
time::cpu_time(End),
|
|
Time is End - Start.
|
|
|
|
|
|
timer(Call, Times, Time) :-
|
|
time::cpu_time(Start),
|
|
loop::forto(1, Times, Call),
|
|
time::cpu_time(End),
|
|
Time is (End - Start) / Times.
|
|
|
|
|
|
:- end_object.
|