473,732 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

clock_t clock() ambiguity

Does clock_t clock() measure real time or process time? Unless I have
missed something, Stroustrup's treatment in TC++PL (section D.4.4.1) is
none too clear on that question.

Is clock() well-implemented for the major compilers g++, VC++, and
Macintosh compilers and other C++ compilers on Linux/Unix, Windows, and
MacOS?
Jul 29 '06
30 17312
Phlip wrote:
Default User wrote:

>>"The clock function tells how much time the calling process has used."

It is not the wall time, it's the process time.


Despite, uh, saying "wall" time at the top of the page?

Please Google [wall-clock time]. If it's meaning isn't related to the
movement of a clock's hands while the program runs, then I'm wrong.
Otherwise, the MSDN page is inconsistent with itself.

A Win32 test involving Sleep() and two clock() calls would instantly answer
questions about the actual implementation.

And please be more careful with your own claims.
Brian's claim is correct.

From C99 7.23.2.1:

The clock function returns the implementation' s best approximation to
the processor time used by the program since the beginning of an
implementation-defined era related only to the program invocation.

--
Ian Collins.
Jul 29 '06 #11
Phlip wrote:
Matt wrote:

>>Does clock_t clock() measure real time or process time? Unless I have
missed something, Stroustrup's treatment in TC++PL (section D.4.4.1) is
none too clear on that question.

Is clock() well-implemented for the major compilers g++, VC++, and
Macintosh compilers and other C++ compilers on Linux/Unix, Windows, and
MacOS?


http://msdn.microsoft.com/library/de..._crt_clock.asp

Note the compatibility is "ANSI", which is MS's code for the "ISO C
Standard". All compilers worth using will have it.

Then note the first line is "Calculates the wall-clock time used by the
calling process." That "wall-clock" is jargon for real time, not process
time. And "used by the calling process" means the "epoch" starts when the
program starts.

In future, please hit a question with Google before posting it! I answered
all your questions with the first citation for [msdn clock_t].
Thanks for your answers to all my two questions!

Your answer to my first question was wrong.

Your answer to my second question was nonexistent.
Aug 1 '06 #12
Matt wrote:
Phlip wrote:
>Matt wrote:

>>Does clock_t clock() measure real time or process time? Unless I
have missed something, Stroustrup's treatment in TC++PL (section
D.4.4.1) is none too clear on that question.

Is clock() well-implemented for the major compilers g++, VC++, and
Macintosh compilers and other C++ compilers on Linux/Unix, Windows,
and MacOS?


http://msdn.microsoft.com/library/de..._crt_clock.asp

Note the compatibility is "ANSI", which is MS's code for the "ISO C
Standard". All compilers worth using will have it.

Then note the first line is "Calculates the wall-clock time used by
the calling process." That "wall-clock" is jargon for real time, not
process time. And "used by the calling process" means the "epoch"
starts when the program starts.

In future, please hit a question with Google before posting it! I
answered all your questions with the first citation for [msdn
clock_t].

Thanks for your answers to all my two questions!

Your answer to my first question was wrong.
In what way was it "wrong"? You asked "real time or process time"? The
answer was 'wall-clock' and the explanation given that it is "real time
not process time". How in hell is it "wrong"?
Your answer to my second question was nonexistent.
The asnwer to your second question was "All complers worth using will have
it". To me it means "implemente d". As to "well" or "not well", we cannot
tell -- it's implementation-specific and we don't discuss implementations .
Most compilers have their own newsgroups, consider posting there. Also,
if you need information on "other compilers for <blahplatform ", please
consider asking in the newsgroup[s] dedicated to the platform[s].

Also, complaining about free advice is non-sensical. You asked a question,
you received _a_ response. Take it or leave it, don't bitch about it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 1 '06 #13

Matt wrote:
Does clock_t clock() measure real time or process time?
[snip]

To add to the confusion, I have just tested a program using clock() on
Solaris and Windows NT. On both platforms clock() did seem to give
wall-clock (that is elapsed) time - the same result as is available
with gettickcount() on windows and time() on Solaris.
To get processor time, I had to use GetProcessInfo on Windows and
getrusage on Solaris (not 100% confident on those last names - i do not
have the code present).

/Peter

Aug 1 '06 #14
peter koch wrote:
Matt wrote:
>Does clock_t clock() measure real time or process time?
To add to the confusion, I have just tested a program using clock() on
Solaris and Windows NT. On both platforms clock() did seem to give
wall-clock (that is elapsed) time - the same result as is available
with gettickcount() on windows and time() on Solaris.
To get processor time, I had to use GetProcessInfo on Windows and
getrusage on Solaris (not 100% confident on those last names - i do not
have the code present).
Did your test use a Sleep(big number)? Sleep's documentation claims it
suspends the CPU activity for a process...

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Aug 1 '06 #15

Phlip wrote:
peter koch wrote:
Matt wrote:
Does clock_t clock() measure real time or process time?
To add to the confusion, I have just tested a program using clock() on
Solaris and Windows NT. On both platforms clock() did seem to give
wall-clock (that is elapsed) time - the same result as is available
with gettickcount() on windows and time() on Solaris.
To get processor time, I had to use GetProcessInfo on Windows and
getrusage on Solaris (not 100% confident on those last names - i do not
have the code present).

Did your test use a Sleep(big number)? Sleep's documentation claims it
suspends the CPU activity for a process...
Yes. I did measure a few busy loops (calculating e.g. sin() repeatedly)
and one sleep for app. six seconds. The results were consistent: clock
gave same result as gettickcount on windows, whereas GetProcessInfo
gave the same results on the busy loops and 0 when calling Sleep.

/Peter
>
--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Aug 1 '06 #16
peter koch wrote:
Yes. I did measure a few busy loops (calculating e.g. sin() repeatedly)
and one sleep for app. six seconds. The results were consistent: clock
gave same result as gettickcount on windows, whereas GetProcessInfo
gave the same results on the busy loops and 0 when calling Sleep.
Thanks. You have restored my faith in MSDN.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Aug 1 '06 #17
Default User wrote:
mlimber wrote:
Matt wrote:
Does clock_t clock() measure real time or process time? Unless I
have missed something, Stroustrup's treatment in TC++PL (section
D.4.4.1) is none too clear on that question.
IIRC, it's not defined by the C or C++ standards.

From the C99 draft standard:
[snip]

Apparently, IIRC = I didn't recall correctly. ;-)

Cheers! --M

Aug 1 '06 #18

Phlip wrote:
peter koch wrote:
Yes. I did measure a few busy loops (calculating e.g. sin() repeatedly)
and one sleep for app. six seconds. The results were consistent: clock
gave same result as gettickcount on windows, whereas GetProcessInfo
gave the same results on the busy loops and 0 when calling Sleep.

Thanks. You have restored my faith in MSDN.
>From the other posts it seems to me that Windows NT as well as Solaris
got it wrong. This also explains my collegues surprise when I told them
that clock() returns elapsed time - they thought that clock() returned
processortime.
Could it be that Solaris and Windows NT shares a flawed codebase from
some time in the distant past?

/Peter
--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Aug 1 '06 #19
Phlip wrote:
peter koch wrote:
Yes. I did measure a few busy loops (calculating e.g. sin()
repeatedly) and one sleep for app. six seconds. The results were
consistent: clock gave same result as gettickcount on windows,
whereas GetProcessInfo gave the same results on the busy loops and
0 when calling Sleep.

Thanks. You have restored my faith in MSDN.
I'm not sure what faith. The documentation is either inconsistent,
confusing, or just wrong.

This whole conversation seemed somewhat familiar, a bit of Groupling
came up with this:

<http://groups.google.com/group/comp....hread/fb0f9076
19ac71fe/7a52324dcae9a6f d>
Victor said then that Microsoft screwed up the implementation of
clock() in Visual Studio, and my little experiment seemed to confirm
that.

Brian
Aug 1 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6695
by: James Harriman | last post by:
Hi, I need to be able to measure a time interval in milliseconds on a windows machine. I have tried using time.clock() but it appears to measure time in seconds...Is there a way to measure time more precisely? Regards, James Harriman v38zy@unb.ca
0
408
by: Peger, Daniel H. | last post by:
Hi, I'm having a slight problem with the precision of the standard c++ clock function as it is defined in time.h . On my system the shortest meassurable time period is 0.01 seconds, but for my programm I need to meassure the processing time in ms. Is there perhaps something like an environment variable controlling the precision of clock(), or is there any other way of meassuring time in ANSI C in the ms domain??
33
47618
by: Pushkar Pradhan | last post by:
I'm using clock() to time parts of my code e.g. clk1 = clock(); /* code */ clk2 = clock(); /* calculate time in secs */ ...... clk1 = clock(); /* code */ clk2 = clock();
54
4007
by: CoreyWhite | last post by:
The following experiment is a demonstration of TIME TRAVEL. When writing this program, and testing it out I found that sometimes the program would engage itself in time travel but other times it would not. After careful testing and reprogramming I have optimized the code so it should work every time, however I recommend that you leave the room while it is running and think of something else. It takes about 5 minuets to run so it is...
12
4097
by: cenktarhancenk | last post by:
is there a way to display a ticking clock in a web page using javascript? but not in a textbox, rather as text that i can change the style, font etc. cenk tarhan
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.