- 论坛徽章:
- 0
|
下面是google论坛上的回复.不过按照他的说法以及楼上大哥的解释,lTime应该不至于误差这么大啊(1.4s之多);
我比较倾向于double类型溢出.但是经我试验好像不会溢出.而且连续运行多次不应该出现有时溢出有时不溢出;
谢谢各位的帮助.
On Feb 11, 7:06 pm, yuanhao1...@gmail.com wrote:
> I hope someone can help me with negative time measurements
> I am
> getting.
Surely i'm doing something silly but cannot find it.
> code:
> struct timeval tvStart,tvEnd;
> double linStart = 0,linEnd = 0,lTime = 0;
> gettimeofday (&tvStart,NULL);
You are using the wrong function. The 'gettimeofday' function gets the
system's best guess at wall time. This *can* go backwards. What you
want is 'clock_gettime(CLOCK_MONOTONIC)' which measures the elaspsed
time from an arbitrary reference time. (Usually the system uptime, but
that's not guaranteed.)
DS
[ 本帖最后由 haohao06 于 2007-2-12 14:56 编辑 ] |
|