[Top][All Lists]

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

inconsistent behavior of 'clock'

From: Mike Miller
Subject: inconsistent behavior of 'clock'
Date: Sat, 20 Mar 1999 23:22:50 -0600 (CST)

I was timing the speed of some operations using the clock and etime
commands.  I noticed that some operations took negative time.  Then I
simply entered the clock command alone several times consecutively, about
1/3 second apart.  These are the numbers that came out:

  1999.0000     3.0000    20.0000    22.0000    23.0000    39.9787
  1999.0000     3.0000    20.0000    22.0000    23.0000    39.2934
  1999.0000     3.0000    20.0000    22.0000    23.0000    40.6958
  1999.0000     3.0000    20.0000    22.0000    23.0000    40.0783
  1999.0000     3.0000    20.0000    22.0000    23.0000    40.4037
  1999.0000     3.0000    20.0000    22.0000    23.0000    41.7554

We can see that time sometimes goes backward.

I have since tried the cputime function and what I find is that the
following line always returns something equal to about 0.65:

t0=cputime; mean(mean(randn(10000,10).^4)>3); cputime-t0

but the following line returns values of approximately 0.65, or 1.65, or
-0.35, varying in a seemingly random way:

t0=clock; mean(mean(randn(10000,10).^4)>3); etime(clock, t0)

So this method, which is recommended in the documentation seems to give a
result that is not correct and is often off by exactly 1.0 second.

I also ran the following command

for i=1:100, X(i,:)=clock; end

and found that values in X(:,6) were ordered, as expected, and consecutive
values differed by about 0.0016, but the value jumped from 55.4990 to
56.5006, a difference of 1.0016 at one point in the sequence.

If anyone knows what causes this, please let me know.  I'm running the
precompiled Octave, version 2.0.13 (sparc-sun-solaris2.5), on Solaris 2.6.  
Maybe I should try to compile it myself, or maybe it wouldn't matter.



Michael B. Miller
University of Missouri--Columbia

reply via email to

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