[erlang-questions] writing a delay loop without now()
Fredrik Svahn
fredrik.svahn@REDACTED
Sat Feb 21 14:12:12 CET 2009
I do not know if it is helpful or not, but with R12B-5 on an AMD Turion
running Arch Linux I consistently get around 5001 milliseconds both with and
without hipe. "erl -smp disable" gives the same results.
Erlang (BEAM) emulator version 5.6.5 [source] [64-bit] [smp:2]
[async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.6.5 (abort with ^G)
1>
erlang:statistics(wall_clock),test:time(5000000),erlang:statistics(wall_clock).
{18066,5001}
2>
erlang:statistics(wall_clock),test:time(1000),erlang:statistics(wall_clock).
{200733,2}
3>
erlang:statistics(wall_clock),test:time(1000),erlang:statistics(wall_clock).
{202005,2}
4>
erlang:statistics(wall_clock),test:time(1000),erlang:statistics(wall_clock).
{203189,2}
BR /Fredrik
On Sat, Feb 21, 2009 at 12:43 AM, James Hague <james.hague@REDACTED> wrote:
> All right, here's a simple case. I hope I'm not doing something dumb
> here. This is only to illustrate one issue; it's not a full analysis
> of timing in Erlang.
>
> First, try this from the shell:
>
>
> erlang:statistics(wall_clock),timer:sleep(5000),erlang:statistics(wall_clock).
>
> I get {57018,5007} which is just about five seconds (the second number
> is the elapsed time between calls. The parameter to sleep is in
> MILLIseconds. (Note that if I change 5000 to 1, I get a result of 16
> milliseconds elapsed on the machine I'm using at the moment. If I
> change it to 16, I get a result of 31 milliseconds.)
>
> Now here's a little function that uses now/0 and timer:now_diff/2 to
> wait for a specified number of MICROseconds:
>
> -module(test).
> -compile(export_all).
>
> time(N) -> time(N, now()).
> time(N, Start) ->
> case timer:now_diff(now(), Start) of
> M when M >= N -> M;
> _ -> time(N, Start)
> end.
>
> Now try it from the shell:
>
>
> erlang:statistics(wall_clock),test:time(5000000),erlang:statistics(wall_clock).
>
> I get {836723,1310} on the same machine. 1.3 seconds.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090221/7183d4ff/attachment.htm>
More information about the erlang-questions
mailing list