r-lib / later

Schedule an R function or formula to run after a specified period of time.
https://r-lib.github.io/later
Other
137 stars 27 forks source link

Feature request: high resolution clock for later? #180

Open dereckmezquita opened 10 months ago

dereckmezquita commented 10 months ago

I'd be interested in using R at high speeds to run an interval with logic.

Can we incorporate a high-resolution clock to run an interval with precision? I want to run at the ms to a microsecond precision level.

Could we somehow leverage Cpp's chrono and high_resolution_clock? Is R capable of running at these speeds?

If worth pursuing I'd be interested in contributing to later to implement this.

shikokuchuo commented 4 months ago

timespec_get() is defined in tinycthread.h in the package source, so this should already be high resolution (down to the nanosecond, but limited by the resolution of the system clock).

The C++ chrono::high_resolution_clock forwards to the same underlying (system-dependent) implementation according to the second answer here: https://stackoverflow.com/questions/12392278/