[m-rev.] diff: benchmark_det_io

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu Sep 26 16:15:07 AEST 2002


This has already been sort-of-reviewed by Fergus.

Zoltan.

library/benchmarking:
	Add a predicate for measuring the performance of predicates
	that do I/O.

NEWS:
	Mention the new predicate.

Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.267
diff -u -b -r1.267 NEWS
--- NEWS	16 Sep 2002 06:07:39 -0000	1.267
+++ NEWS	26 Sep 2002 06:07:16 -0000
@@ -260,6 +260,8 @@
 
 * New convenience/readability predicates `int__even/1' and `int__odd/1'.
 
+* New predicate benchmark_det_io for benchmarking code that performs I/O.
+
 * We've removed the long obsolete `int__builtin_*' and
   `float__builtin_float_*' predicates, which were synonyms
   for the arithmetic functions dating from when Mercury didn't
Index: library/benchmarking.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.51
diff -u -b -r1.51 benchmarking.m
--- library/benchmarking.m	21 Aug 2002 11:27:32 -0000	1.51
+++ library/benchmarking.m	22 Aug 2002 05:19:17 -0000
@@ -49,6 +49,10 @@
 :- pred benchmark_func(func(T1) = T2, T1, T2, int, int).
 :- mode benchmark_func(func(in) = out is det, in, out, in, out) is cc_multi.
 
+:- pred benchmark_det_io(pred(T1, T2, T3, T3), T1, T2, T3, T3, int, int).
+:- mode benchmark_det_io(pred(in, out, di, uo) is det, in, out, di, uo,
+		in, out) is cc_multi.
+
 % benchmark_nondet(Pred, In, Count, Repeats, Time) is for benchmarking
 % the nondet predicate Pred. benchmark_nondet is similar to benchmark_det,
 % but it returns only a count of the solutions, rather than solutions
@@ -634,6 +638,32 @@
 		impure benchmark_func_loop(Func, In, Out, Repeats - 1)
 	;
 		Out = Out0
+	).
+
+:- pragma promise_pure(benchmark_det_io/7).
+benchmark_det_io(Pred, InA, OutA, InB, OutB, Repeats, Time) :-
+	impure get_user_cpu_miliseconds(StartTime),
+	impure benchmark_det_loop_io(Pred, InA, OutA, InB, OutB, Repeats),
+	impure get_user_cpu_miliseconds(EndTime),
+	Time = EndTime - StartTime.
+	% XXX cc_multi_equal(Time0, Time).
+
+:- impure pred benchmark_det_loop_io(pred(T1, T2, T3, T3), T1, T2,
+	T3, T3, int).
+:- mode benchmark_det_loop_io(pred(in, out, di, uo) is det, in, out,
+	di, uo, in) is cc_multi.
+
+benchmark_det_loop_io(Pred, InA, OutA, InB, OutB, Repeats) :-
+	% The call to do_nothing/1 here is to make sure the compiler
+	% doesn't optimize away the call to `Pred'.
+	Pred(InA, OutA0, InB, OutB0),
+	impure do_nothing(OutA0),
+	( Repeats > 1 ->
+		impure benchmark_det_loop_io(Pred, InA, OutA, OutB0, OutB,
+			Repeats - 1)
+	;
+		OutA = OutA0,
+		OutB = OutB0
 	).
 
 :- pragma promise_pure(benchmark_nondet/5).
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list