in reply to Call function no more than every 0.1 seconds

The simple solution:

What to do with "missed" samples is up to you. The obvious choices are to start the next sample immediately and to calculate the next desired sampling time and resume on an interval boundary. Which of these you want depends on what you are doing with the data.

  • Comment on Re: Call function no more than every 0.1 seconds

Replies are listed 'Best First'.
Re^2: Call function no more than every 0.1 seconds
by Marshall (Canon) on Aug 12, 2020 at 03:18 UTC
    I like this idea. This Is like a "throttle" to reduce number of requests per second.
    Sounds pretty good to me. But be aware that execution will not happen on .1 sec intervals.

      It will get very close. The delay is calculated after the work for "this" cycle has been done. The accuracy is limited by the accuracy of whatever you use to implement the delay, of course, and the system scheduler might preempt your process, but this can be limited by keeping the load reasonable. As I understand, a load average less than the number of processors means that all tasks are (on average) being run whenever they are not blocked.