r-lib / later

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

Feature request: high resolution clock for later? #180

Open dereckmezquita opened 1 year ago

dereckmezquita commented 1 year 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 6 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/