I’ve been working on some code that requires getting the delta between loops. I was just curious if there is a method that you can use to get that or if it requires storing the last timestamp and calculating the difference between them.
That’s pretty much the definition of it, yeah. There’s nothing automatic to get that in any language AFAIK- you’d have to tell the compiler what loop time you want calculated, and at that point you’re back to the complexity of store+difference, which is about 3 lines total.
Some languages have some good libraries, especially for small snippits of code. But under the hood yeah, it’s the difference between two times.
Have you looked at the timer class?
FWIW we did wrapper the operation into two methods:
We do the calculation of both “our code execution duration” and “periodic call rate”, and store them into our data-logging infrastructure.
But, at its core, yea, it’s the three lines mentioned above.
Yes, I’ve been using
getFPGATimestamp() to get the time, I just didn’t know if there was a cleaner way to do it since it seems so common
How about the start, get, and reset methods of the timer class?
Yes, I suppose that wold work as well.