Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > clock() problem

Reply
Thread Tools

clock() problem

 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-12-2005
"Ufit" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
 
Ufit
Guest
Posts: n/a
 
      01-12-2005
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
 
Reply With Quote
 
 
 
 
Rickard Nisses-Gagnér
Guest
Posts: n/a
 
      01-12-2005
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" <(E-Mail Removed)> skrev i meddelandet
news:cs2drs$qr6$(E-Mail Removed)...
> 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



 
Reply With Quote
 
Lionel B
Guest
Posts: n/a
 
      01-12-2005
Rickard Nisses-Gagnér wrote:
>
> /Rickard
> "Ufit" <(E-Mail Removed)> skrev i meddelandet
> news:cs2drs$qr6$(E-Mail Removed)...
> > 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments