Solved

c++ clock() function problem in windows

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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: …
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 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.

821 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