-
Notifications
You must be signed in to change notification settings - Fork 601
Description
Where
Time::HiRes
Description
The Time::HiRes documentation shows invocations of clock_gettime(CLOCK_REALTIME), but in the example there is no import of CLOCK_REALTIME.
The code in question gives the impression that it is correct when executed on Linux as CLOCK_REALTIME seems to map to 0 anyways, but not on Windows:
Windows
$ perl -MTime::HiRes=clock_gettime,CLOCK_REALTIME -e 'print(CLOCK_REALTIME, "\n");'
1
Linux
$ perl -MTime::HiRes=clock_gettime,CLOCK_REALTIME -e 'print(CLOCK_REALTIME, "\n");'
0
I'm not a perl expert by any means but it looks like some kind of implicit conversion to 0 is happening when the import of CLOCK_REALTIME is missing. I know use strict; will find this but it's a subtle detail.
The lack of import threw me since I have very little familiarity with perl, so I had assumed these constants were just available globally because the documentation did not import them, so it looked like I had used it correctly when I tested on Linux but was giving me all -1 values on Windows.
Not using strict but only executing this kind of code could cause subtle issues for anyone that wants CLOCK_MONOTONIC semantics. We do use strict, but I was writing up a quick test-case to ensure I was using the API properly since I was resolving a timing drift problem that only happens on Windows for us when using Time::HiRes::time() and it threw me for a loop.
Just in case version matters at all here:
# Version on Windows
$ perl --version
This is perl 5, version 32, subversion 1 (v5.32.1) built for i686-cygwin-threads-64int-multi
(with 6 registered patches, see perl -V for more detail)
# Version on Linux
❯ perl --version
This is perl 5, version 34, subversion 0 (v5.34.0) built for x86_64-linux-gnu-thread-multi
(with 57 registered patches, see perl -V for more detail)