This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/examples/profiling/timer.lgt
2001-06-06 19:40:57 +00:00

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.