[erlang-questions] Add hibernate/1 (was: Best practice for defining functions with edoc,erlc,eunit and the dialyzer)

Richard O'Keefe <>
Mon Dec 7 03:21:27 CET 2009


On Dec 5, 2009, at 6:58 PM, Alpár Jüttner wrote:
> I can see another (very small) class:
>     (D) functions to be invoked by timer:tc/3.

This should be added to my quasi-EEP about hibernate/3.
It is in fact another class where there *shouldn't* be
an internal export, but it's forced because the library
isn't up to date yet.  I have revised my quasi-EEP to
include

     Add the following code to stdlib/src/timer.erl

     %%
     %% Measure the execution time (in microseconds) for a Fun.
     %%
     -spec tc(fun(() -> T)) -> {time(), T}.
     tc(Fun) when is_function(Fun, 0) ->
         Before = erlang:now(),
         Value = (catch Fun()),
         After = erlang:now(),
         {now_diff(After, Before), Value}.

     Add the following documentation for timer:

     tc(Fun)

         Types:
             Fun = fun()

         Evaluates Fun() and measures the elapsed real time.
         Returns {Time, Value}, where Time is the elapsed real time in
         microseconds, and Value is what is returned by the Fun().






More information about the erlang-questions mailing list