cputime() returns incorrect values

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

cputime() returns incorrect values

Anton Dereventsov
This post was updated on .
The following simple script generates and multiplies two random 1000-by-1000
matrices for 20 iterations and measures how long (in terms of both the
wall-clock time and the cpu time) each iteration was executing.

Here is the code:
for i = 1 : 20
	t0 = tic;
	t1 = cputime;
	rand(1000) * rand(1000);
	printf('wall time: %.6f  |  cpu time: % .6f\n', toc(t0), cputime-t1);
endfor

And here is the output that I get:
wall time: 0.071920  |  cpu time:  0.031200
wall time: 0.071924  |  cpu time:  0.124800
wall time: 0.062927  |  cpu time:  0.062402
wall time: 0.056930  |  cpu time:  0.062400
wall time: 0.055934  |  cpu time:  1.000000
wall time: 0.056937  |  cpu time:  0.000000
wall time: 0.059940  |  cpu time:  0.093600
wall time: 0.055943  |  cpu time:  0.000000
wall time: 0.057947  |  cpu time:  1.000000
wall time: 0.068950  |  cpu time:  0.062400
wall time: 0.072955  |  cpu time: -0.781598
wall time: 0.062958  |  cpu time:  0.062400
wall time: 0.056961  |  cpu time:  0.000000
wall time: 0.055964  |  cpu time:  1.000000
wall time: 0.055968  |  cpu time:  0.000000
wall time: 0.060971  |  cpu time:  0.062400
wall time: 0.055974  |  cpu time:  1.000000
wall time: 0.068978  |  cpu time:  0.062402
wall time: 0.076982  |  cpu time:  0.156000
wall time: 0.074987  |  cpu time:  0.312002

The wall-clock time measured by tic-toc is believable but the cpu time is
clearly false: sometimes it is negative and sometimes it is exactly 0 or 1.
These particular results were obtained in Octave 4.2.2 on Windows 7 machine
with Intel i7-3610QM cpu but I observed the similar output on Ubuntu 16.04
with Intel Xeon E3-1535M v6.
Coincidentally, in Matlab the same code on the same machines returns
reasonable cpu time.
Is this a bug or am I doing something terribly wrong?

Thanks,
Anton



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: cputime() returns incorrect values

nrjank
On Sun, Sep 2, 2018, 11:33 Anton Dereventsov <[hidden email]> wrote:
.

Here is the code:


And here is the output that I get:



Your code and output didn't come through in the mailing list emails. Can you resend in plain text?


Reply | Threaded
Open this post in threaded view
|

Re: cputime() returns incorrect values

Anton Dereventsov
Sure, sorry about that. Here is the full message:

The following simple script generates and multiplies two random 1000-by-1000 matrices for 20 iterations and measures how long (in terms of both the wall-clock time and the cpu time) each iteration was executing.

Here is the code:
for i = 1 : 20
t0 = tic;
t1 = cputime;
rand(1000) * rand(1000);
printf('wall time: %.6f  |  cpu time: % .6f\n', toc(t0), cputime-t1);
endfor

And here is the output that I get:
wall time: 0.071920  |  cpu time:  0.031200
wall time: 0.071924  |  cpu time:  0.124800
wall time: 0.062927  |  cpu time:  0.062402
wall time: 0.056930  |  cpu time:  0.062400
wall time: 0.055934  |  cpu time:  1.000000
wall time: 0.056937  |  cpu time:  0.000000
wall time: 0.059940  |  cpu time:  0.093600
wall time: 0.055943  |  cpu time:  0.000000
wall time: 0.057947  |  cpu time:  1.000000
wall time: 0.068950  |  cpu time:  0.062400
wall time: 0.072955  |  cpu time: -0.781598
wall time: 0.062958  |  cpu time:  0.062400
wall time: 0.056961  |  cpu time:  0.000000
wall time: 0.055964  |  cpu time:  1.000000
wall time: 0.055968  |  cpu time:  0.000000
wall time: 0.060971  |  cpu time:  0.062400
wall time: 0.055974  |  cpu time:  1.000000
wall time: 0.068978  |  cpu time:  0.062402
wall time: 0.076982  |  cpu time:  0.156000
wall time: 0.074987  |  cpu time:  0.312002

The wall-clock time measured by tic-toc is believable but the cpu time is clearly false: sometimes it is negative and sometimes it is exactly 0 or 1.
These particular results were obtained in Octave 4.2.2 on Windows 7 machine with Intel i7-3610QM cpu but I observed the similar output on Ubuntu 16.04 with Intel Xeon E3-1535M v6.
Coincidentally, in Matlab the same code on the same machines returns reasonable cpu time.
Is this a bug or am I doing something terribly wrong?

Thanks,
Anton


Anton

On Sun, Sep 2, 2018 at 12:38 PM, Nicholas Jankowski <[hidden email]> wrote:
On Sun, Sep 2, 2018, 11:33 Anton Dereventsov <[hidden email]> wrote:
.

Here is the code:


And here is the output that I get:



Your code and output didn't come through in the mailing list emails. Can you resend in plain text?



Reply | Threaded
Open this post in threaded view
|

Re: cputime() returns incorrect values

Dmitri A. Sergatskov


On Sun, Sep 2, 2018 at 11:51 AM Anton Dereventsov <[hidden email]> wrote:
Sure, sorry about that. Here is the full message:

The following simple script generates and multiplies two random 1000-by-1000 matrices for 20 iterations and measures how long (in terms of both the wall-clock time and the cpu time) each iteration was executing.

Here is the code:
for i = 1 : 20
t0 = tic;
t1 = cputime;
rand(1000) * rand(1000);
printf('wall time: %.6f  |  cpu time: % .6f\n', toc(t0), cputime-t1);
endfor

And here is the output that I get:
wall time: 0.071920  |  cpu time:  0.031200
wall time: 0.071924  |  cpu time:  0.124800
wall time: 0.062927  |  cpu time:  0.062402
wall time: 0.056930  |  cpu time:  0.062400
wall time: 0.055934  |  cpu time:  1.000000
wall time: 0.056937  |  cpu time:  0.000000
wall time: 0.059940  |  cpu time:  0.093600
wall time: 0.055943  |  cpu time:  0.000000
wall time: 0.057947  |  cpu time:  1.000000
wall time: 0.068950  |  cpu time:  0.062400
wall time: 0.072955  |  cpu time: -0.781598
wall time: 0.062958  |  cpu time:  0.062400
wall time: 0.056961  |  cpu time:  0.000000
wall time: 0.055964  |  cpu time:  1.000000
wall time: 0.055968  |  cpu time:  0.000000
wall time: 0.060971  |  cpu time:  0.062400
wall time: 0.055974  |  cpu time:  1.000000
wall time: 0.068978  |  cpu time:  0.062402
wall time: 0.076982  |  cpu time:  0.156000
wall time: 0.074987  |  cpu time:  0.312002

The wall-clock time measured by tic-toc is believable but the cpu time is clearly false: sometimes it is negative and sometimes it is exactly 0 or 1.

 
I can reproduce this on Fedora with 4.2.2. it works fine with the current stable (4.4.1) version.

wall time: 0.112784  |  cpu time:  0.109635
wall time: 0.102103  |  cpu time:  0.101593
wall time: 0.098640  |  cpu time:  0.098136
wall time: 0.101773  |  cpu time:  0.101256
wall time: 0.097494  |  cpu time:  0.096882
wall time: 0.096570  |  cpu time:  0.096078
wall time: 0.097592  |  cpu time:  0.097008
wall time: 0.096049  |  cpu time:  0.095532
wall time: 0.096685  |  cpu time:  0.096213
wall time: 0.096337  |  cpu time:  0.095828
wall time: 0.097368  |  cpu time:  0.096865
wall time: 0.096752  |  cpu time:  0.096263
wall time: 0.096347  |  cpu time:  0.095957
wall time: 0.095746  |  cpu time:  0.095232
wall time: 0.096550  |  cpu time:  0.096025
wall time: 0.095373  |  cpu time:  0.094902
wall time: 0.095917  |  cpu time:  0.095407
wall time: 0.095301  |  cpu time:  0.094794
wall time: 0.097900  |  cpu time:  0.097243
wall time: 0.096106  |  cpu time:  0.095624


Dmitri.
--



On Sun, Sep 2, 2018 at 12:38 PM, Nicholas Jankowski <[hidden email]> wrote:
On Sun, Sep 2, 2018, 11:33 Anton Dereventsov <[hidden email]> wrote:
.

Here is the code:


And here is the output that I get:



Your code and output didn't come through in the mailing list emails. Can you resend in plain text?




Reply | Threaded
Open this post in threaded view
|

Re: cputime() returns incorrect values

Anton Dereventsov
Indeed, it works fine in Octave 4.4.1.
Thanks!



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html