Solved

c++ clock() function problem in windows

Posted on 2009-04-01
2
1,425 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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 column That will then direct you to their download page. From that p…
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 synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

632 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