coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] sleep: allow ms suffix for milliseconds


From: Bernhard Voelker
Subject: Re: [PATCH] sleep: allow ms suffix for milliseconds
Date: Fri, 29 Nov 2019 18:38:19 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2

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

[Prev in Thread] Current Thread [Next in Thread]