[erlang-questions] writing a delay loop without now()

tsuraan <>
Mon Mar 2 22:37:43 CET 2009


> The kernel is different though ("2.6.20-1.2320.fc5smp"), probably glibc
> too, but I have a hard time believing that either of those is the cause.
> I don't suppose that you run some primitive time-keeping app that keeps
> whacking the system time around? (The above system runs NTP.)

I'm running 2.6.28 (vanilla) and glibc 2.6.1.  Ntp is running in the
background, but I don't think it's constantly messing with the system
clock, at least not so much that it would cause these sorts of
results.

It's a gentoo system; everything is compiled with arch=i686 and O2.  I
imagine that fedora uses at least O2 for everything, but are they
still supporting pentium1 (arch=i586)?  I think that could slow things
down a little, maybe.

> What number do you get with the loop-counting version I posted earlier
> (time2/1 reposted below)? I get numbers like 4559687, which is
> uncomfortably close to 1 call per microsecond but still just below - I
> think it would have to be some 25% faster on your system to produce the
> above result. I guess it's possible even if unlikely...

Just doing time2 (no wall_clock) reliably gives me {4999999,5000000}.
If I do wall_clock, I pretty reliably get 4200 elapsed ms.

>
> If you do get just about 5000000 (it can never be more), maybe you could
> try the "twiddle" version (time3/1 below) too?

That works really well, even with c(test, native):

20> erlang:statistics(wall_clock),test:time3(5000000),erlang:statistics(wall_clock).
{112133,5001}
21> erlang:statistics(wall_clock),test:time3(5000000),erlang:statistics(wall_clock).
{117927,5000}
22> erlang:statistics(wall_clock),test:time3(5000000),erlang:statistics(wall_clock).
{123552,5001}

Also, my raw numbers for time2 (without native compilation) are:

17> erlang:statistics(wall_clock),test:time2(5000000),erlang:statistics(wall_clock).
{93637,4199}
18> erlang:statistics(wall_clock),test:time2(5000000),erlang:statistics(wall_clock).
{98664,4158}
19> erlang:statistics(wall_clock),test:time2(5000000),erlang:statistics(wall_clock).
{103691,4200}



More information about the erlang-questions mailing list