VB.NET 对多个事物进行计时,最好有多个秒表或一个秒表并计算偏移量
VB.NET 2010,.NET 4
您好,
我有一个控制进程的应用程序和几个跟踪自各种事件以来经过的时间的秒表。
简化的图是:过程开始,稍后发生事件“A”,稍后发生事件“B”,等等......
此类事件的数量是有限的。在每个事件(包括流程启动事件)开始时,我创建并启动一个新的秒表。然后,我更新一些显示自每个事件开始以来的时间量的指示器。
因此,我有一堆标签(LabelStart、LabelA、LabelB 等),每个标签的格式为 HH:MM:SS,表示自每个事件发生以来经过的时间。它们的文本源自相应秒表的属性。
我的问题是,拥有一个秒表和一个偏移整数列表(从 CPU/内存效率的角度来看)会更好吗?即,秒表在进程启动时启动,并且在每个事件处,等于该秒表上当前经过的毫秒数的整数被添加到列表中。然后可以通过从正在运行的秒表中减去偏移量来更新标签。
我不知道它们是如何工作的。也许这是一个愚蠢的问题。我只是好奇。
提前致谢! 布莱恩
VB.NET 2010, .NET 4
Hello,
I have an application which controls a process and several stopwatches that keep track of the elapsed time since various events.
The simplified picture is: The process starts, at a later time an event "A" occurs, at a later time an event "B" occurs, etc...
There are a finite number of such events. At the start of each event (including the process start event), I create and start a new stopwatch. I then update some indicators that display the amount of time since each event started.
So, I have a bunch of labels (LabelStart, LabelA, LabelB, etc) each formatted as HH:MM:SS which represent the elapsed time since each event occurred. Their text is derived from the corresponding stopwatchs' properties.
My question is, would it be better to have one stopwatch and a list of offset integers (from a CPU/memory efficiency standpoint)? I.e., the stopwatch starts at process start and, at each event, an integer equal to the current elapsed milliseconds on that stopwatch is added to a list. The labels could then be updated by subtracting the offset from the one running stopwatch.
I have no idea how they work. Maybe this is a dumb question. I'm just curious.
Thanks in advance!
Brian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在开发计算机应用程序,并且 SEVERAL 不是太多(例如少于 10 个),那么应该没有任何区别。
但你的思考方式会让事情变得更有效率。
If you are developing application for computers and if SEVERAL is not too much like less than 10 it should not make any difference.
But the way you are thinking will make it more efficient.
秒表类型本身是一个结构,而不是一个类,它本质上包含一个“模式”指示以及一个数字,该数字要么代表经过的滴答数(当它不运行时),要么代表它所处的系统性能计数器值。应该被视为已经开始(当它运行时)。一个包含一百万个 StopWatch 实例(全部在不同时间启动)的数组不会比任何其他类似大小的结构数组带来更多的持续开销。
The stopwatch type itself is a structure, rather than a class, and it essentially contains a "mode" indication along with a number that either represents the number of ticks elapsed (when it's not running), or the system performance counter value at which it should be deemed to have started (when it is running). An array holding a million
StopWatch
instances, all started at different times, would impose no more continuing overhead than any other array of similarly-sized structures.