Will a large number of timers affect the timing of the timer?

If I have a large number of timers (10 to maybe a couple hundred) all with <100ms interval, will it affect any of them firing?

+2


source to share


4 answers


Logically not, but in practice I assume that you can find their performance limited by the physical limitations of the processor.



I suspect you will want to go back to your design.

+3


source


It will, but I don't know if you will see it.

If you have a 1 GHz machine. Then one clock cycle is 1 nanosecond (1 / 1.000.000.000). Let's say that a set of timers takes 10 clock cycles (maybe more is needed, but just a thought experiment). Then 100 sets of timers would take 1 microsecond.



But there are many other variables that you need to consider for a real life example, but that should help you understand what's going on.

+2


source


Which timer class are you using? Many standard timers have low resolution and probably shouldn't be used for intervals less than 100ms. See here for an example of a higher resolution timer.

As said, you should rethink your design as having 10 or 100 seconds of timers is unnecessarily complicated and a waste of resources. A single 1ms high resolution timer can be used for 1ms more timeslots - just count how many times the timer has started. If you have multiple intervals to track, use a 1ms timer with multiple counters, one per interval. So for an interval of 100ms, when the timer counter reaches 100, the interval has expired (then you will need to reset that counter to 0).

+1


source


First of all, it depends on whether you are using System.Timers.Timer

or System.Windows.Forms.Timer

.

The window timers will run on the main thread, so a single handler cannot start until the preview ends. The timer is never guaranteed to start at exactly the right time, but if you have a lot of them, they will influence each other.

Timers are less sensitive since the handlers run on separate threads, but the processor still can't run more threads at the same time than there are cores, so they can still interfere somewhat with each other.

0


source







All Articles