Solved

c++ clock() function problem in windows

Posted on 2009-04-01
2
1,422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
rendaduiyan earned 250 total points
ID: 24046635
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
ID: 24049197
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

751 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