问题标签 [gettimeofday]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1187 浏览

c++ - C++ gettimeofday() 返回相同的值

为什么它不规则地显示相同的时间?(在 ubuntu 64 位和 C++ 上编译)还有哪些其他标准方法可用于生成毫秒精度的 unix 时间戳?

0 投票
0 回答
109 浏览

c - 返回值与实际返回值不符

我有一个函数将当前的 gettimeofday 值作为双精度值返回。问题是我在函数内部看到的返回值与在函数外部分配的值不同。

这是一个 gdb 片段 -

如您所见, 的值STARTtime!

START定义为double START

如何找出导致此问题的原因?

0 投票
4 回答
2982 浏览

objective-c - Objective-c gettimeofday 函数替代方案

我在我的程序中使用 gettimeofday 这样的时间间隔:

有没有其他选择?

0 投票
1 回答
212 浏览

timer - C Linux 中的计时器

我试图使用 gettimeofday 创建一个计时器。已调用函数“time”来重置和获取计时器的当前时间。但是当我试图获得第二齿值时,程序给出了垃圾值。请帮忙

0 投票
3 回答
12445 浏览

c - time() and gettimeofday() return different seconds

On the two systems I've tested (a 32-bit Ubuntu 12.04 server and a 64-bit Ubuntu 13.10 VM), the seconds since the epoch given by time() may differ from gettimeofday()'s.

Specifically, though I call time() after calling gettimeofday(), the value returned by time() is sometimes less than the tv_sec value returned by gettimeofday().

This apparently occurs just after the clock rolls over to a new second.

This caused bugs in some of my code that expected time()'s and gettimeofday()'s seconds to be interchangeable.

Sample code demonstrating this problem:

Note that I'm calling time() second and only complaining if its value is less than gettimeofday()'s.

Sample output:

I.e., the two values were the same 33 million times, they were different 177k times, and they were always different within 5844 microseconds of a new second.

Is this a known issue? What causes this?

0 投票
1 回答
1829 浏览

null - Swift:gettimeofday 和不安全指针

Swift 中的代码

Objective C 中的代码

我一直在尝试查找有关 UnsafePointer 的更多信息以及传递 NULL 的替代方法,但我可能会找错树。

如果有人知道如何让等价代码在 Swift 中运行,那就太好了。如果对发生的事情有一个很好的解释,那就更好了!

0 投票
1 回答
203 浏览

c - cudaEvent 和 gettimeofday 报告的时间完全不同

我正在尝试使用 gettimeofday 或 cudaEventRecord 来计时循环。然而,他们报告了非常不同的结果。这是伪代码:

我没有同时使用它们,而是分别使用它们,结果不一样。在使用 cudaEvent 时,我还调用了 cudaEventSynchrosize(stop)。谢谢。

0 投票
1 回答
1956 浏览

linux - gettimeofday() 有时会返回负值

对于下面的代码,我有时会得到负值。我不明白这一点。任何人都可以解释为什么会发生这种情况。

0 投票
1 回答
168 浏览

timer - 使用 gettimeofday() 进行自校正周期性定时器

我有一个循环,它运行每个 X usecs,其中包括执行一些 I/O,然后为剩余的 X usecs 休眠。为了(粗​​略地)计算睡眠时间,我所做的就是在 I/O 之前和之后取一个时间戳,然后从 X 中减去差值。这是我用于时间戳的函数:

正如你可以想象的那样,它开始漂移得非常快,并且 I/O 突发之间的实际时间通常比 X 长几毫秒。为了让它更准确一点,我想如果我记录一下上一个起始时间戳,每次我开始一个新周期时,我都可以计算上一个周期花费了多长时间(这个起始时间戳和上一个时间戳之间的时间)。然后,我知道它比 X 长了多少,我可以为这个周期修改我的睡眠来补偿。

这是我尝试实现它的方式:

它似乎在循环的第一次迭代中起作用,但是在那之后事情变得一团糟。

这是循环 5 次迭代的输出:

输出的第一行显示了上一个周期时间是如何计算的。看来前两个时间戳基本上相隔 1000000us(1412452353 - 1411452348 = 1000005)。然而,在此之后,起始时间戳之间的距离以及偏移量开始看起来不太合理。有谁知道我在这里做错了什么?

编辑:我也欢迎提出更好的方法来获得准确的计时器并在延迟期间能够入睡!

0 投票
1 回答
170 浏览

c - 超线程对 gettimeofday 和其他时间测量的影响

当我在 C 语言中使用 BLAS 矩阵运算对超线程 CPU 进行基准测试时,我观察到使用超线程时函数的运行时间几乎翻了一番。由于乱序执行或其他优化,我期望的是某种速度的提高。

我使用 gettimeofday 来估计运行时间。为了评估观察结果,我想知道您是否对 gettimeofday 在超线程环境(Debian Linux 32 位)中的稳定性或我的期望(他们可能是错误的)有想法?

更新:我忘了提到我正在运行基准测试应用程序两次,每次都将亲和性设置为一个超线程核心。例如 gemm 并行运行两次。