But, is there a real differences for example in term of performance?
Of course there are differences, since they are different functions, and it all depends on how they are implemented which might differ between operating systems, but that's not something to be measured within perl as explained below.
(The following applies to the Linux kernel 3.16.) On a Linux system, both sleep and select boil down to system calls, sleep being implemented via nanosleep(2) and select via select(2) (the 2 in parens indicate the manual page section, which is "system calls" on my system.)
With both calls, perl notifies the kernel of a timeout for the function, after which program execution should continue, so performance differences depend on the respective kernel implementations. Since select(2) takes more arguments (e.g. filehandles) than, the kernel might allocate more resources for this specific call than nanosleep(2), but the call could internally be optimized to nanosleep(2) - I don't know and won't look.
As others pointed out, perl's sleep (for compatibility reasons?) takes only the integer part of a decimal number, and negative values for sleep are wrapped around to positive values. Absolute values below 0 (e.g. -0.2345) are considered 0 and the call is then optimized away.
qwurx [shmem] ~> strace -e trace=nanosleep perl -e 'sleep 1'
nanosleep({1, 0}, 0x7ffe9dc8df90) = 0
+++ exited with 0 +++
qwurx [shmem] ~> strace -e trace=nanosleep perl -e 'sleep 0.123456'
+++ exited with 0 +++
qwurx [shmem] ~> strace -e trace=nanosleep perl -e 'sleep -1'
nanosleep({4294967295, 0}, ^CProcess 27923 detached
<detached ...>
qwurx [shmem] ~> strace -e trace=nanosleep perl -e 'sleep 3.1415926'
nanosleep({3, 0}, 0x7ffed4b7b6a0) = 0
+++ exited with 0 +++
qwurx [shmem] ~> strace -e trace=select perl -e 'select $u,$u,$u, 3.14
+15926'
select(0, NULL, NULL, NULL, {3, 141592}) = 0 (Timeout)
+++ exited with 0 +++
qwurx [shmem] ~> strace -e trace=select perl -e 'select $u,$u,$u, -3.1
+415926'
select(0, NULL, NULL, NULL, {0, 0}) = 0 (Timeout)
+++ exited with 0 +++
The timeout argument of select(2) is struct timeval, which on my system is
struct timeval
{
__time_t tv_sec; /* Seconds. */
__suseconds_t tv_usec; /* Microseconds. */
};
so select(2) can be called with fractions of a second as timeout. Values below zero, however, are just set to 0.
In summary, for any difference of perfomance to be measured within perl, one would have to emit huge amounts of either system call to get some difference, which for sleep implies interruption of each system call for the test to terminate before you grow old; and even then, you would just measure the kernel's performance for each call from perl's point of view. The results probably would be misleading, since the kernel has other things to do than providing timeouts for a benchmark script; and there are other tools to profile the kernel.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
|