1

I'm currently doing a research which I need to implement high precision sleep function, within 10-100 (us) microsecond accuracy, is there has any possible method I can achieve that? I tried to use time.sleep(50/1000000), but it not working. This code is I tried in my Mac,

import time

print(time.time())
seconds = 10
time.sleep(seconds/1000000.0)
print(time.time())

The accuracy is closer to 1000 us, but I hope to get higher precision.

If Python cannot achieve that, is there any other language can achieve that?

leo0807
  • 941
  • 1
  • 8
  • 21
  • According to https://stackoverflow.com/questions/5568646/usleep-in-python this should work though. Can you be more specific on whats not working. – Buddy Bob Jun 15 '22 at 15:52
  • 1
    According to https://stackoverflow.com/questions/1133857/how-accurate-is-pythons-time-sleep, you can not achieve precision in microsecond, but just on millisecond. It's a limitation on OS, you it appears that it is not possible to do that despite of the function you are using. – Vítor Cézar Jun 15 '22 at 15:56
  • Updated, so is there any other language or other OS I can achieve that? – leo0807 Jun 15 '22 at 16:04
  • My guess would be if any language can do it it will be C++ or C – Mark Jun 15 '22 at 16:08
  • Baased on @VítorCézar's comment, this really does seem like a hardware limitation that you'll have a hard time getting around just by changing languages. You might find better luck on [superuser](https://superuser.com/), [hardware recommendations](https://hardwarerecs.stackexchange.com/), or another [stackexchange site](https://stackexchange.com/sites). – Michael Delgado Jun 15 '22 at 16:38
  • just curious - what research are you doing where you need this kind of precision? – Michael Delgado Jun 15 '22 at 16:42

0 Answers0