Search code examples
vb.netperformancetimingstopwatch

VB.NET Timing multiple things, better to have many stopwatches or one stopwatch and calculate offsets


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


Solution

  • 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.