help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pause(.01) gives a mean pause of 0.0102 and not 0.0100 seconds


From: Francesco Potortì
Subject: Re: pause(.01) gives a mean pause of 0.0102 and not 0.0100 seconds
Date: Fri, 18 Oct 2019 10:23:51 +0200

ingo:
>inor0627 wrote
>> for ii=1:100
>> t0=tic();
>> do
>>   t(ii)=toc(t0);
>> until (t>0.01)
>> end%for
>> t_mean=mean(t)
>> 
>>>> t_mean =    10.0051e-003  ?
>
>Of course it should be:
>...
>until (t(ii)>=0.01)
>...

At least in principle, this accumulates error.  Moreover it is a tight
loop, meaning that it uses up all the cpu time.

The next one is along the lines that I had mentioned before: it does not
eccumulate error, and limits the tight loop to a fraction slack/intv of the
CPU time.  slack should be increased on a heavy loaded machine.  The
current 1ms value is good only if the box has very light load.


N=1000
t=zeros(N,1)
intv=10e-3
slack=1e-3
t0=tic()
for ii=1:N
  pause(intv-slack)
  do
    t(ii)=toc(t0)
  until (t(ii)>=ii*intv)
endfor

statistics(diff(t))
ans =
   0.009951115
   0.009986997
   0.009999990
   0.010015011
   0.010046959
   0.009999983
   0.000019990
  -0.005423515
   2.507219921

-- 
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it




reply via email to

[Prev in Thread] Current Thread [Next in Thread]