On 2019-11-29 14:30, Rasmus Villemoes wrote:
> When one wants to sleep for some number of milliseconds, one can
> do (at least in bash)
> 
>   sleep $(printf '%d.%03d' $((x/1000)) $((x%1000)))
> 
> but that's a bit cumbersome.

Why not use floating-point numbers directly?

  $ sleep 0.01234

Calling sleep(1) with a small milliseconds argument seems anyway a very
rough hammer, because the overhead to launch the executable is larger
than the actual nanosleep(2) system call.

  $ for i in $(seq 10); do time sleep 0.00345 ; done 2>&1 | grep real
  real  0m0.006s
  real  0m0.004s
  real  0m0.005s
  real  0m0.005s
  real  0m0.005s
  real  0m0.005s
  real  0m0.004s
  real  0m0.004s
  real  0m0.005s
  real  0m0.005s

As such, I'm only 30:70 to support the 'ms' suffix (or even 'ns').

Have a nice day,
Berny


Reply via email to