473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

clock() problem

I must precisely measure the time of calculation.
f.ex

clock_t begin,finish,time;
begin=clock();
Calculations();
finish=clock();
time=finish-begin;

but unfortunatelly finish is equal to begin
sth like begin=56789 and finish=56789
They give me 0. How else can I measure the time very precisely?
Please help.
Thanks

Ufit
Jul 22 '05 #1
3 2126
"Ufit" <ko**************@NOpoczta.fm> wrote...
I must precisely measure the time of calculation.
f.ex

clock_t begin,finish,time;
begin=clock();
Calculations();
finish=clock();
time=finish-begin;

but unfortunatelly finish is equal to begin
sth like begin=56789 and finish=56789
They give me 0. How else can I measure the time very precisely?


You can do more Calculations:

begin=clock();
for (int i=0; i < 1000000; i++)
Calculations();
finish=clock();

or you can use a finer time measurement. Not available in the
Standard C++, but look in your OS programming manual or ask in
the newsgroup dedicated to your OS.

V
Jul 22 '05 #2
In Windows you can use GetTickCount() function in Kernel32.dll, just include
windows.h
This function retrievs the number of milliseconds since the computer was
started
And ofcourse use Victors advice!

/Rickard
"Ufit" <ko**************@NOpoczta.fm> skrev i meddelandet
news:cs**********@news.onet.pl...
I must precisely measure the time of calculation.
f.ex

clock_t begin,finish,time;
begin=clock();
Calculations();
finish=clock();
time=finish-begin;

but unfortunatelly finish is equal to begin
sth like begin=56789 and finish=56789
They give me 0. How else can I measure the time very precisely?
Please help.
Thanks

Ufit

Jul 22 '05 #3
Rickard Nisses-Gagnér wrote:

/Rickard
"Ufit" <ko**************@NOpoczta.fm> skrev i meddelandet
news:cs**********@news.onet.pl...
I must precisely measure the time of calculation.
f.ex

clock_t begin,finish,time;
begin=clock();
Calculations();
finish=clock();
time=finish-begin;

but unfortunatelly finish is equal to begin
sth like begin=56789 and finish=56789
They give me 0. How else can I measure the time very precisely?
Please help.
Thanks

Ufit

<OT (system-dependent)>
In Windows you can use GetTickCount() function in Kernel32.dll,
just include windows.h
This function retrievs the number of milliseconds since the computer
was started
.... but with a resolution of +/- 10ms (depending on your system) I
believe. On Win NT, QueryPerformanceFrequency() and
QueryPerformanceCounter() (declared in <winbase.h>) are likely to give
you much higher resolution.

</OT>
And ofcourse use Victors advice!


Yes; it will always be unreliable to time just one invocation of a
(fast) function.

--
Lionel B

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Agency | last post by:
I'm still working on the bpm counter. I need to have at least 2 displays that are not static. One would be a clock/running time and the other would should the current beat count. How would I...
3
by: Szabolcs Nagy | last post by:
I have to measure the time of a while loop, but with time.clock i always get 0.0s, although python manual sais: "this is the function to use for benchmarking Python or timing algorithms" So i...
0
by: Peger, Daniel H. | last post by:
Hi, I'm having a slight problem with the precision of the standard c++ clock function as it is defined in time.h . On my system the shortest meassurable time period is 0.01 seconds, but for my...
33
by: Pushkar Pradhan | last post by:
I'm using clock() to time parts of my code e.g. clk1 = clock(); /* code */ clk2 = clock(); /* calculate time in secs */ ...... clk1 = clock(); /* code */ clk2 = clock();
54
by: CoreyWhite | last post by:
The following experiment is a demonstration of TIME TRAVEL. When writing this program, and testing it out I found that sometimes the program would engage itself in time travel but other times it...
4
by: Shawn Yates | last post by:
I am fairly new to MS Access and VB but thanks to many of the posts on this site I have found solutions to my problems. I have been searching all day, however, for an answer to my current problem...
2
by: cpptutor2000 | last post by:
Could some C guru suggest some possible solution to my problem? I am trying to simulate a clock and I have tried using 'gettimeofday' and some related C library functions, but I am not getting what...
5
by: Charles May | last post by:
Anyone have a simple concept for the best way to store timeclock information in a database. I currently have my table set up like this with a typical daily entry. tcID empID Type ...
7
by: Godzilla | last post by:
Hello, I have been reading a thread about time.clock() going backward, which is exactly what I am seeing... the thread generally leaning toward the problem is caused by multi-processor machines....
8
by: Theo v. Werkhoven | last post by:
hi, In this code I read out an instrument during a user determined period, and save the relative time of the sample (since the start of the test) and the readback value in a csv file. #v+...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.