Clock() question

T

Tadeusz Jordan

Hello,

Could anyone tell me what are the units of the value returned by the
function clock()? I thought they are CLOCKS_PER_SECs of a second but my
prof. crossed them out on my report.

Thanks for any help.

Tadeusz
 
L

Lionel B

Hello,

Could anyone tell me what are the units of the value returned by the
function clock()? I thought they are CLOCKS_PER_SECs of a second but my
prof. crossed them out on my report.

Might your prof. have been looking for the answer 1/CLOCKS_PER_SEC ... ?
 
L

Lionel B

Might your prof. have been looking for the answer 1/CLOCKS_PER_SEC ... ?

Make that 1/CLOCKS_PER_SEC *seconds*. Apparently POSIX requires that
CLOCKS_PER_SEC = 1000000, so I guess "seconds/1000000" might be an
acceptable answer.
 
J

Juha Nieminen

Tadeusz said:
Could anyone tell me what are the units of the value returned by the
function clock()? I thought they are CLOCKS_PER_SECs of a second but my
prof. crossed them out on my report.

My guess is that your professor didn't know the language standard
well enough to know that clock() and CLOCKS_PER_SEC are indeed standard
(well, according to its linux manpage they are).
 
J

James Kanze

Make that 1/CLOCKS_PER_SEC *seconds*. Apparently POSIX requires that
CLOCKS_PER_SEC = 1000000, so I guess "seconds/1000000" might be an
acceptable answer.

Only if the subject matter was modern Unix, and not C or C++.
(On many of the older compilers I've used, the value was
typically 50 or 60, depending on whether the machine was in
Europe or the US.)
 
L

Lionel B

Only if the subject matter was modern Unix, and not C or C++.

Um, what about C or C++ on a POSIX system? AFAIK clock() is standard C
(and C++) while CLOCKS_PER_SEC = 1000000 is mandatory on a POSIX stystem.
This is why I said "*might* be an acceptable answer" (sorry if that
wasn't clear).
 
L

Lionel B

My guess is that your professor didn't know the language standard
well enough to know that clock() and CLOCKS_PER_SEC are indeed standard
(well, according to its linux manpage they are).

CLOCKS_PER_SEC may indeed be standard but it is not the units of the
value returned by the clock(). "1/CLOCKS_PER_SEC seconds" is.
 
T

Tadeusz Jordan

Lionel B said:
CLOCKS_PER_SEC may indeed be standard but it is not the units of the
value returned by the clock(). "1/CLOCKS_PER_SEC seconds" is.

"1/CLOCKS_PER_SEC seconds" is that an equivalent statement to
"CLOCKS_PER_SECs of a second" ?

Tadeusz
 
L

Lionel B

Please don't quote sigs
"1/CLOCKS_PER_SEC seconds" is that an equivalent statement to
"CLOCKS_PER_SECs of a second" ?

Not quite: "CLOCKS_PER_SEC-ths of a second" ;) Try this for eg.
CLOCKS_PER_SEC = 1000
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top