Boost logo

Boost Users :

Subject: Re: [Boost-users] A problem on using boost timer (different time intervals were showed). Can any one with kindness help me?
From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2009-09-24 04:01:38


fmingu wrote:
> I am using boost timer in C++ builder 2009 to test the time used in
> my program.there are the lines:
> ....................
> boost::timer t;
> double timeresult;
> ...................
>
> t.restart();
> ........... //my program main body
> timeresult=t.elapsed();
> ShowMessage( " the time consumed by my program is
> "+FloatToStr(timeresult));
> .........................
> the program was compiled and linked and worked well.
> But I find a problem:
> every time the message showed is not the same time interval,
> sometimes it is 0.015 and sometimes it is 0.016 and sometimes it is 0.
> I do not know how it was happened.

There's nothing strange with that.

> Does it happen due to the multi-process and multi-thread mode by
> windows?

No, it happens because the actual resolution of the timer under Windows is
platform-dependent, and on your platform ~15ms. If the exection takes less
time, you'll see 0 elapsed.

> I do not know how to solve it. My program is quite strict on the time
> consumed by the computer.

Run the program's main body many times and divide the total time with the
number of executions.

HTH / Johan


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net