[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: alculating elapsed time using clock() returns invalid values on an AMD64 box
- From: Rick Stevens <rstevens vitalstream com>
- To: Thiago Guzella <thiago guzella gmail com>, For users of Fedora Core releases <fedora-list redhat com>
- Cc:
- Subject: Re: alculating elapsed time using clock() returns invalid values on an AMD64 box
- Date: Mon, 04 Oct 2004 13:28:30 -0700
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 vitalstream com -
- VitalStream, Inc. http://www.vitalstream.com -
- -
- Blech! ACKth! Ooop! -- Bill the Cat (Outland) -
----------------------------------------------------------------------
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]