如果在我测量间隔时发生时间变化,会发生什么情况,例如:
gettimeofday(&start, NULL);
system("./anotherProgram");
// during the execution of another program, time changes
gettimeofday(&end, NULL);
elapsed = (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
经过
会增加/减少一个小时吗?
在 Unices 上,gettimeofday
始终从 the Epoch 开始线性测量时间。 。本地时间转换和夏令时与此无关,完全不会影响它。
不过,我现在并不知道 Windows 上的情况如何。过去,当 DST 切换发生时,Windows 实际上更改了硬件时钟,我认为这也会影响 thời gian
Và gettimeofday
返回的内容,但我不能说实话我对 Windows 非常了解。我也不知道情况是否仍然如此。
如果有的话,您可能需要注意 leap seconds ,但它们一开始就很少见(更不用说它们不会对您的程序产生太大影响),如果我没记错的话,ntpd
之类的东西会在一段时间内使它们变得平滑。然而,我对后者的看法可能是错误的。
如果您想要一个实际的、单调递增的时间,您应该考虑使用clock_gettime(ĐỒNG HỒ ĐƠN GIẢN, ...)
。
Tôi là một lập trình viên xuất sắc, rất giỏi!