Re: alculating elapsed time using clock() returns invalid values on an AMD64 box

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

 



Thiago Guzella wrote:
Hi there folks,

I have got an AMD64 system running fedora core 2. It's an Athlon64
3500+, on an Asus A8V Deluxe.
I have found something quite intriguing, by running the following code:

------------------

...
clock_t start, end;

start = clock();

// Do some work

end = clock();

elapsed_time = (double) (end - start) / (double) CLOCKS_PER_SEC;

------------------

The calculated time for an specific program i've written is 32.83
seconds, but the time i have calculated by looking at a digital watch
before and after program execution was 125 seconds.
My question is: i am doing something wrong?? Has the clock() way of
measuring elapsed time been deprecated? If so, how should I do it?

If you carefully read the man page for clock(), you'd find:

"The clock() function returns an approximation of processor time used by
the program."

Note that's _processor_ time, not elapsed time.  For elapsed time, use
"time(2)" (return current time in seconds since the epoch of 00:00:00
UTC, January 1, 1970).
----------------------------------------------------------------------
- Rick Stevens, Senior Systems Engineer     rstevens@xxxxxxxxxxxxxxx -
- VitalStream, Inc.                       http://www.vitalstream.com -
-                                                                    -
-           Blech!  ACKth!  Ooop!  -- Bill the Cat (Outland)         -
----------------------------------------------------------------------


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux