[erlang-questions] negative diference between two calls to now/0

Samuel Rivas samuelrivas@REDACTED
Mon Feb 5 08:51:33 CET 2007


Rodrigo Ahumada M. wrote:
> [...]
> so i made a program that launches N processes that tries to conect to
> the server, send question and receive an answer. After that the process
> send its results to a logger process and then terminates.
> 
> the code for each process is like this:
> 
> [...]
> 
> time_lapse({_MgS1, S1, MuS1}, {_MgS2, S2, MuS2}) ->
>   %% calculate the difference of msecs,
>   %% ignore the MegaSecs because always they're zero
>   T1 = S1*1000 + MuS1,
>   T2 = S2*1000 + MuS2,
>   T2 - T1.
> [...]

  MuS1 and MuS2 are microseconds, not milliseconds. Also, megaseconds
difference is not always zero. Each about 11.5 days it changes, so if 
you ignore then you will get negative values if, for example, you get

 {828, 1, 653753} - {827, 999999, 676}

(example from supervisor.erl)

Regards
-- 
	Samuel



More information about the erlang-questions mailing list