n900 - maemo - 计时
我试图在 +- 100 毫秒内每秒保存一个文件(10% 错误)。我遇到的问题是,我的计时测量表明执行花费了 1150 毫秒,但实际上它似乎是 3 或 4 秒。
这是怎么回事?
如果我发出命令 sleep(1),它看起来非常准确。然而,当我测量某件事需要多长时间时,它肯定会偏离相当多。
我正在使用 Clock() 来测量程序执行情况。所有这些东西都在 while 循环内。
瓦尔特
I am attempting to save a file every second within +- 100ms (10% error). The problem I am having is that my timing measurement is saying that execution took 1150 ms, but in reality it appears to be 3 or 4 seconds.
What's going on?
If I issue the command, sleep(1), it appears to be very accurate. However, when I measure how long something took, it must be off by quite a bit.
I am using clock() to measure program execution. All of this stuff is within a while loop.
Walter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是
clock()
报告您的进程使用的 CPU 时间,它通常与使用的“真实”时间不同。例如下面的代码:
给出
Your problem is that
clock()
reports you CPU time used by your process and it is usually different from the "real" time used.For example following code:
gives