.NET 中 System.nanoTime() 的等效项是什么?
标题几乎是不言自明的,我正在为这种简单而自杀。
看了这里,但没有多大帮助。
The title is pretty much self-explanatory, I'm killing myself over this simplicity.
Looked here, but it isn't much helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我认为 Stopwatch 类就是你的意思寻找。
I think that the Stopwatch class is what you are looking for.
如果您希望在 GNU/Linux 和 Windows(至少 7 个)下的不同进程、不同语言(Java、C、C#)之间比较时间戳:
Java:
C GNU/Linux:
C Windows:
C#:
If you want a timestamp to be compared between different processes, different languages (Java, C, C#), under GNU/Linux and Windows (Seven at least):
Java:
C GNU/Linux:
C Windows:
C#:
DateTime.Now
将为您提供以毫秒为单位的当前时间,但精确到纳秒的时间是相当不切实际的,至少在 Windows 中是这样。DateTime.Now
will give you the current time in milliseconds, but time that is accurate to nanoseconds is fairly impractical, at least in Windows.我能找到的最接近的是 DateTime.ToFileTime() 方法。您可以在 DateTime 的实例上调用此方法,如下所示:
该方法返回 Windows 文件时间:
您至少可以将时间间隔缩短至 100 ns。
src: http://msdn.microsoft.com/en-我们/library/system.datetime.tofiletime.aspx
the closest thing that i could find is the DateTime.ToFileTime() method. you can call this on an instance of a DateTime like so:
The method returns a Windows File Time:
you could at least time down to 100 ns intervals with it.
src: http://msdn.microsoft.com/en-us/library/system.datetime.tofiletime.aspx
DateTime.Now.Ticks
我试图找到这个问题的答案来运行一些性能测试。
DateTime.Now.Ticks
I was trying to find the answer to this to run some performance testing.
我认为如果您以纳秒为单位进行计时,您将达到操作系统的硬限制。这是一篇关于该主题的好文章:
http://www.lochan。 org/2005/keith-cl/useful/win32time.html
虽然 Windows 很乐意返回 100 纳秒的精度,但时钟只能保证每 15.6 毫秒左右更新一次。因此,Windows 会有效地将这些更新发生的时间返回到 100 纳秒的精度。为了比这更准确,您可能需要准备编写 C 或汇编程序并运行嵌入式操作系统。
I think you're going to hit the hard limits of the OS if you're timing in nanoseconds. Here's a good article on the topic:
http://www.lochan.org/2005/keith-cl/useful/win32time.html
While Windows will happily return 100 nanosecond accuracy, the clock is only guaranteed to update once every 15.6 milliseconds or so. So effectively Windows returns the time at which those updates occurred to 100 nanosecond accuracy. For more accuracy than this you probably need to be prepared to write C or assembler and run and embedded OS.
http://msdn.microsoft.com/de-de/library /system.datetime.ticks.aspx
类似:DateTime.Ticks
http://msdn.microsoft.com/de-de/library/system.datetime.ticks.aspx
somelike: DateTime.Ticks