How long does it take for a line of code to run?

I am experimenting with getting position via integrating the inertial sensor value, but for this I would need a very accurate time between measurements. So I was wondering how long it takes the Brain the execute a line of code?

Literally millaseconds it’s super fast ther should be no problem

1 Like

Its not the speed that’s the problem, its knowing the time between measurements. I need something to multiply the velocity and acceleration values by to determine my position and velocity.

There’s a difference between getting “a very accurate time between measurements” and how long each instruction takes to execute. Though it may also be the case that you need both for this.

The timer class that Vex provides returns timestamps with millisecond resolution:

There does look to be a function that returns timestamps in microseconds: systemHighResolution

There is also the rate at which the IMU reports new values, which I believe is 20 msec, though @jpearman would be the best source of correct information.

EDIT: I believe the IMU also has a timestamp function that will return the time of the last reading; I believe the resolution is milliseconds.

AFAIK, others have tried to use this method with this sensor before and none have been successful in getting reasonable results. But it is an interesting exercise to try, and something unique to add for your Engineering Notebook, regardless of whether your implementation succeeds.