可秒表生产code使用? [英] Can Stopwatch be used in production code?

查看:138
本文介绍了可秒表生产code使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个精确的计时器和DateTime.Now似乎不够准确。从我读的描述,System.Diagnostics.Stopwatch似乎正是我想要的。

I need an accurate timer, and DateTime.Now seems not accurate enough. From the descriptions I read, System.Diagnostics.Stopwatch seems to be exactly what I want.

但我有恐惧症。我担心使用任何在实际生产中code System.Diagnostics程序。 (我用它广泛用于调试断言和PrintLns等,但从来没有生产的东西。)我不只是试图用一个定时器基准我的功能 - 我的应用程序需要一个实际的定时器。我读过的另一个论坛,System.Diagnostics.StopWatch只为标杆,而不应在零售code被使用,但没有给出原因。这是正确的,还是我(和谁张贴的意见)是太封闭了头脑有关System.Diagnostics程序?也就是说,它是确定生产code使用System.Diagnostics.Stopwatch?
谢谢
阿德里安

But I have a phobia. I'm nervous about using anything from System.Diagnostics in actual production code. (I use it extensively for debugging with Asserts and PrintLns etc, but never yet for production stuff.) I'm not merely trying to use a timer to benchmark my functions - my app needs an actual timer. I've read on another forum that System.Diagnostics.StopWatch is only for benchmarking, and shouldn't be used in retail code, though there was no reason given. Is this correct, or am I (and whoever posted that advice) being too closed minded about System.Diagnostics? ie, is it ok to use System.Diagnostics.Stopwatch in production code? Thanks Adrian

推荐答案

引擎盖下,pretty多少都秒表做的是包装的 QueryPerformanceCounter的。据我了解,秒表是有提供访问高分辨率定时器 - 如果你需要这个分辨率在生产中code我看不出什么毛病,使用它

Under the hood, pretty much all Stopwatch does is wrap QueryPerformanceCounter. As I understand it, Stopwatch is there to provide access to the high-resolution timer - if you need this resolution in production code I don't see anything wrong with using it.

这篇关于可秒表生产code使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆