🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #227

Collecting timing statistics

#227
From: David J. Barker-Plummer
Date: Thu, 22 Jun 1989 22:23
62 lines
2380 bytes
Can anyone explain the following phenomenon which occurs when I try to
collect runtime statistics for a program.  I am running Quintus 2.3 on
a SUN Workstation running SunOS 4.0.

I have written the following code for timing a goal:

	runtime(Goal, Time) :-
		statistics(runtime, _),
		call(Goal),
		statistics(runtime, [_,Time]).

Wishing to take the average time over a number of runs I implemented
the obvious (to me) recursive procedure which calls the goal some
specified number of times, collecting the returned runtimes into a
list (ensuring that a new copy of the goal is used each time).  To my
surprise, the list of runtimes returned were in increasing order, with
frequently a factor of two increase over the list.

Thinking that the timing procedure was somehow adding to the runtime,
I reimplemented the collection procedure to be a failure-driven bounce
which runs the Goal, asserts the runtime and then fails back to before
the call to the goal to repeat the specified number of times.  Still
the reported runtimes increase for later runs, and still major changes
in the reported results.

My questions.  Can anyone explain this phenomenon? and Can anyone
supply an approved method of collecting runtimes to be averaged.  In
case the description of the above two procedures are not clear, they
are appended.

Thanks for any help -- Dave

---- Version 1 ----

rec_collect_times(_, 0, []).
rec_collect_times(Goal, N, [Time|Times]) :-
	N > 0,
	copy_term(Goal, GoalCopy),
	runtime(GoalCopy, Time),
	M is N-1,
	rec_collect_times(Goal, M, Times).

---- Version 2 ----

%%%%    Exceeding Ugly Code Alert    %%%%

fdb_collect_times(Goal, Count, Times) :-
	nat(N),
	((N =< Count -> 
	     ( runtime(Goal, Time),
	       assert(time(Time)),		
	       fail ) )
	;
	bagof(Time, time(Time), Times)).

nat(1).
nat(N) :- nat(M), N is M+1.

------------------------------------------------------------

Dave Barker-Plummer			plummer@cs.duke.edu
Technical Details
Message-ID: <14835@duke.cs.duke.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!ncsuvx!mcnc!duke!juliet!plummer

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!ncsuvx!mcnc!duke!juliet!plummer
From: plummer@juliet.cs.duke.edu (David J. Barker-Plummer)
Newsgroups: comp.lang.prolog
Subject: Collecting timing statistics
Keywords: Timing Benchmarking Statistics
Message-ID: <14835@duke.cs.duke.edu>
Date: 22 Jun 89 22:23:53 GMT
Sender: news@duke.cs.duke.edu
Lines: 62