Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

c++ clock() function problem in windows

Posted on 2009-04-01
2
Medium Priority
?
1,427 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 1000 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 1000 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

Industry Leaders: 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

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: …
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.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

715 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