Solved

c++ clock() function problem in windows

Posted on 2009-04-01
2
1,409 Views
Last Modified: 2013-12-14
I want to use clock() to get time.
But the code below

while (1)
printf("clock: %d\n", clock());

get the results like:

100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
100
116
116
116
116
116
116
116
116
116
116
116
116
116
116
116
116
116
116
116
116
I think it should get sth like 8,9,10,11...or 8,8,8,9,9,9,10,10....
while (1)

printf("clock: %d\n", clock());

Open in new window

0
Comment
Question by:rxzang
2 Comments
 
LVL 5

Accepted Solution

by:
rendaduiyan earned 250 total points
Comment Utility
clock is not so accurate. please refer to http://technology.chtsai.org/w98timer/.
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 250 total points
Comment Utility
rendaduiyan is right. clock only would be actualized any 15/16 milliseconds even on Windows Versions younger than W98.  

You would need to use QueryPerfomanceCounter to get better results. Or for emasuring performance you would need to repeat the measured action - say 1 million of times - to get useable times for comparing.

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now