[m-rev.] diff: implement benchmarking for erlang

Peter Wang novalazy at gmail.com
Tue Sep 25 11:53:12 AEST 2007


Estimated hours taken: 0.5
Branches: main

library/benchmarking.m:
	Implement `report_stats' and do_nothing for Erlang backend.

	Add a comment that the benchmark_* procedures have a side effect on
	`report_stats' in Erlang (fixing this raises its own issues).

README.Erlang:
	Remove `benchmarking' and `dir' from the completely unimplemented
	library modules list.


Index: README.Erlang
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/README.Erlang,v
retrieving revision 1.3
diff -u -r1.3 README.Erlang
--- README.Erlang	5 Sep 2007 04:28:09 -0000	1.3
+++ README.Erlang	25 Sep 2007 01:56:52 -0000
@@ -191,9 +191,7 @@
 
    The following standard library modules are completely unimplemented:
 
-	benchmarking
 	bit_buffer
-	dir
 	thread
 	thread.semaphore
 	time
Index: library/benchmarking.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.76
diff -u -r1.76 benchmarking.m
--- library/benchmarking.m	10 May 2007 05:24:15 -0000	1.76
+++ library/benchmarking.m	25 Sep 2007 01:56:52 -0000
@@ -27,6 +27,9 @@
     % some memory and time usage statistics about the time period since
     % the last call to report_stats to stderr.
     %
+    % Note: in Erlang, the benchmark_* procedures will change the apparent time
+    % of the last call to report_stats.
+    %
 :- impure pred report_stats is det.
 
     % `report_full_memory_stats' is a non-logical procedure intended for use
@@ -170,6 +173,13 @@
     ML_report_full_memory_stats();
 ").
 
+:- pragma foreign_proc("Erlang",
+    report_stats,
+    [may_call_mercury, terminates],
+"
+    'ML_report_stats'()
+").
+
 %-----------------------------------------------------------------------------%
 
 :- pragma foreign_code("C", "
@@ -712,6 +722,20 @@
 }
 ").
 
+:- pragma foreign_code("Erlang",
+"
+'ML_report_stats'() ->
+    {Time, TimeSinceLastCall} = statistics(runtime),
+    TimeSecs = Time / 1000.0,
+    TimeSinceLastCallSecs = TimeSinceLastCall / 1000.0, 
+
+    {value, {total, Bytes}} = lists:keysearch(total, 1, erlang:memory()),
+    KBytes = Bytes / 1024.0,
+
+    io:format(""[Time: ~.3fs, +~.3fs, Total used: ~.3fk]~n"",
+        [TimeSecs, TimeSinceLastCallSecs, KBytes]).
+").
+
 %-----------------------------------------------------------------------------%
 
 :- pragma promise_pure(benchmark_det/5).
@@ -852,6 +876,13 @@
     }
 ").
 
+:- pragma foreign_proc("Erlang",
+    get_user_cpu_milliseconds(Time::out),
+    [will_not_call_mercury],
+"
+    {Time, _TimeSinceLastCall} = statistics(runtime)
+").
+
 /*
 ** To prevent the C compiler from optimizing the benchmark code
 ** away, we assign the benchmark output to a volatile global variable.
@@ -899,6 +930,13 @@
     ML_benchmarking_dummy_word = X;
 ").
 
+:- pragma foreign_proc("Erlang",
+    do_nothing(_X::in),
+    [will_not_call_mercury, thread_safe],
+"
+    void
+").
+
 %-----------------------------------------------------------------------------%
 
 %  Impure integer references.

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list