Skip Menu |

This queue is for tickets about the Time-HiRes CPAN distribution.

Report information
The Basics
Id: 93359
Status: rejected
Priority: 0/
Queue: Time-HiRes

People
Owner: Nobody in particular
Requestors: tpb [...] pervici.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Fwd: [perl #121268] bug in Windows version of Time::HiRes::usleep(EXPR) when EXPR is <1000
Date: Tue, 25 Feb 2014 13:43:10 -0500
To: bug-Time-HiRes [...] rt.cpan.org
From: Thomas Bolioli <tpb [...] pervici.com>
There is a bug in the Time ::HiRes on windows. usleep is only good to 1 millisecond. To get microsecond resolution, here is the below code that needs to be used on windows. See below for the context and test cases. Tom WSADATA wsaData; int iResult; iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iResult != NO_ERROR) { wprintf(L"WSAStartup failed with error: %d\n", iResult); return 1; } void usleep(long millisec){ if (millisec >= 1){ Sleep(millisec); return; } long usec = millisec * 1000; timeval tv; SOCKET sTimer = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); fd_set dummy; FD_ZERO(&dummy); FD_SET(sTimer, &dummy); tv.tv_sec = usec/1000000L; tv.tv_usec = usec%1000000L; select(0, 0, 0, &dummy, &tv); } Begin forwarded message: Show quoted text
> From: "Tony Cook via RT" <perlbug-followup@perl.org> > Subject: [perl #121268] bug in Windows version of Time::HiRes::usleep(EXPR) when EXPR is <1000 > Date: February 24, 2014 at 6:37:55 AM EST > To: tpb@pervici.com > Reply-To: perlbug-followup@perl.org > > On Mon Feb 17 21:01:25 2014, tpb@pervici.com wrote:
>> >> First off, most of what you will need is in the code. There is a bug in Time::HiRes on Windows 7 x64 on a rather high end workstation (dual quad procs). The problem is in usleep and it manifests itself whenever you call a microsecond sleep less than 1000. If you set a value for EXPR in usleep(EXPR) that is less than 1000 (ie; expr <= 999) then it doesn't try to sleep, it simply executes and moves on reporting a sleep time of, on average, .307 microseconds of sleep for that statement. The problem is, if it was working correctly, it should have slept for 999 microseconds, give or take, totaling roughly 1 second for 1000 iterations. But it takes 0.000948905944824219 seconds to run a 1000 iteration loop and not 1 second. When you run something 1000 microseconds or more as the expr to usleep(), it works correctly and it takes 1 second to usleep(1000) 1000 times in a loop. >> >> I am running the latest active state perl, etc; there is code to reproduce the problem below, the output of perl -v as well as perlbug. >> >> Thanks, >> Tom >> >> On a 4 yr old MacBook Pro with perl v5.16.2 >> $ perl time.pl >> # of microseconds per try: 1000 >> total sleep time: 1081814 >> number of trys: 1000 >> avg sleep: 1081.814 >> total time: 1.08898782730103 >> >> # of microseconds per try: 999 >> total sleep time: 1084063 >> number of trys: 1000 >> avg sleep: 1084.063 >> total time: 1.09197998046875 >> >> # of microseconds per try: 10000 >> total sleep time: 10796557 >> number of trys: 1000 >> avg sleep: 10796.557 >> total time: 10.805773973465 >> >> >> On windows: (see version info below) >> C:\CSA\perl tests>perl time.pl >> # of microseconds per try: 1000 >> total sleep time: 993225 >> number of trys: 1000 >> avg sleep: 993.225 >> total time: 1.00008797645569 >> >> # of microseconds per try: 999 >> total sleep time: 307 >> number of trys: 1000 >> avg sleep: 0.307 >> total time: 0.000948905944824219 >> >> # of microseconds per try: 10000 >> total sleep time: 9993387 >> number of trys: 1000 >> avg sleep: 9993.387 >> total time: 10.0006461143494 >> >> using this code: >> >> >> use strict; >> use warnings; >> use Time::HiRes qw(usleep time); >> >> my $trys = 1000; >> my $total = 0; >> my $sleeptry = 1000; >> >> my $start = time(); >> foreach my $i (1..$trys) { >> my $SleepTime = usleep($sleeptry); >> $total += $SleepTime; >> } >> my $end = time(); >> >> print('# of microseconds per try: ',$sleeptry,"\n"); >> print('total sleep time: ',$total, "\n"); >> print('number of trys: ',$trys, "\n"); >> print('avg sleep: ',$total/$trys, "\n"); >> print('total time: ',$end-$start , "\n\n"); >> >> $sleeptry = 999; >> $total = 0; >> $start = time(); >> foreach my $i (1..$trys) { >> my $SleepTime = usleep($sleeptry); >> $total += $SleepTime; >> } >> $end = time(); >> >> print('# of microseconds per try: ',$sleeptry,"\n"); >> print('total sleep time: ',$total, "\n"); >> print('number of trys: ',$trys, "\n"); >> print('avg sleep: ',$total/$trys, "\n"); >> print('total time: ',$end-$start , ā€œ\n\nā€); >> >> $sleeptry = 10000; >> $total = 0; >> >> $start = time(); >> foreach my $i (1..$trys) { >> my $SleepTime = usleep($sleeptry); >> $total += $SleepTime; >> } >> $end = time(); >> >> print('# of microseconds per try: ',$sleeptry,"\n"); >> print('total sleep time: ',$total, "\n"); >> print('number of trys: ',$trys, "\n"); >> print('avg sleep: ',$total/$trys, "\n"); >> print('total time: ',$end-$start , "\n\n"); >> >> perlbug -d output >> >> --- >> Flags: >> category=core >> severity=low >> --- >> Site configuration information for perl 5.16.3: >> >> Configured by cyg_server at Wed Mar 13 13:27:24 2013. >> >> Summary of my perl5 (revision 5 version 16 subversion 3) configuration: >> >> Platform: >> osname=MSWin32, osvers=5.2, archname=MSWin32-x64-multi-thread >> uname='' >> config_args='undef' >> hint=recommended, useposix=true, d_sigaction=undef >> useithreads=define, usemultiplicity=define >> useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef >> use64bitint=define, use64bitall=undef, uselongdouble=undef >> usemymalloc=n, bincompat5005=undef >> Compiler: >> cc='C:\Perl64\site\bin\gcc.exe', ccflags ='-DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DWIN64 -DCONSERVATIVE -DPERL_TEXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DHASATTRIBUTE -fno-strict-aliasing -mms-bitfields', >> optimize='-O2', >> cppflags='-DWIN32' >> ccversion='', gccversion='gcc.exe (rubenvb-4.5.4) 4.5.4', gccosandvers='' >> intsize=4, longsize=4, ptrsize=8, doublesize=8, byteorder=12345678 >> d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8 >> ivtype='__int64', ivsize=8, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8 >> alignbytes=8, prototype=define >> Linker and Libraries: >> ld='C:\Perl64\site\bin\g++.exe', ldflags ='-L"C:\Perl64\lib\CORE"' >> libpth=\lib >> libs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 -lmsvcrt >> perllibs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 -lmsvcrt >> libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl516.lib >> gnulibc_version='' >> Dynamic Linking: >> dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' >> cccdlflags=' ', lddlflags='-mdll -L"C:\Perl64\lib\CORE"' >> >> Locally applied patches: >> ACTIVEPERL_LOCAL_PATCHES_ENTRY >> >> --- >> @INC for perl 5.16.3: >> C:/Perl64/site/lib >> C:/Perl64/lib >> . >> >> --- >> Environment for perl 5.16.3: >> HOME (unset) >> LANG (unset) >> LANGUAGE (unset) >> LD_LIBRARY_PATH (unset) >> LOGDIR (unset) >> PATH=C:\Perl64\site\bin;C:\Perl64\bin;C:\Python33\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Services\IPT\;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Dell\Dell Data Protection\Access\Advanced\Wave\Gemalto\Access Client\v5\;C:\Program Files (x86)\Security Innovation\SI TSS\bin\;C:\Program Files (x86)\Windows Live\Shared >> PERL_BADLANG (unset) >> SHELL (unset) >> >> >> C:\CSA\perl tests>perl -V >> Set up gcc environment - gcc.exe (rubenvb-4.5.4) 4.5.4 >> Summary of my perl5 (revision 5 version 16 subversion 3) configuration: >> >> Platform: >> osname=MSWin32, osvers=5.2, archname=MSWin32-x64-multi-thread >> uname='' >> config_args='undef' >> hint=recommended, useposix=true, d_sigaction=undef >> useithreads=define, usemultiplicity=define >> useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef >> use64bitint=define, use64bitall=undef, uselongdouble=undef >> usemymalloc=n, bincompat5005=undef >> Compiler: >> cc='C:\Perl64\site\bin\gcc.exe', ccflags ='-DNDEBUG -DWIN32 -D_CONSOLE -DNO_ >> STRICT -DWIN64 -DCONSERVATIVE -DPERL_TEXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL >> _IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DHASATTRIBUTE -fno-strict-al >> iasing -mms-bitfields', >> optimize='-O2', >> cppflags='-DWIN32' >> ccversion='', gccversion='gcc.exe (rubenvb-4.5.4) 4.5.4', gccosandvers='' >> intsize=4, longsize=4, ptrsize=8, doublesize=8, byteorder=12345678 >> d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8 >> ivtype='__int64', ivsize=8, nvtype='double', nvsize=8, Off_t='__int64', lsee >> ksize=8 >> alignbytes=8, prototype=define >> Linker and Libraries: >> ld='C:\Perl64\site\bin\g++.exe', ldflags ='-L"C:\Perl64\lib\CORE"' >> libpth=\lib >> libs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 >> -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 - >> lodbccp32 -lcomctl32 -lmsvcrt >> perllibs=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshel >> l32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc >> 32 -lodbccp32 -lcomctl32 -lmsvcrt >> libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl516.lib >> gnulibc_version='' >> Dynamic Linking: >> dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' >> cccdlflags=' ', lddlflags='-mdll -L"C:\Perl64\lib\CORE"' >> >> >> Characteristics of this binary (from libperl): >> Compile-time options: HAS_TIMES HAVE_INTERP_INTERN MULTIPLICITY >> PERLIO_LAYERS PERL_DONT_CREATE_GVSV >> PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS >> PERL_MALLOC_WRAP PERL_PRESERVE_IVUV PL_OP_SLAB_ALLOC >> USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES >> USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE >> USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF >> USE_SITECUSTOMIZE >> Locally applied patches: >> ActivePerl Build 1603 [296746] >> Built under MSWin32 >> Compiled at Mar 13 2013 13:31:10 >> @INC: >> C:/Perl64/site/lib >> C:/Perl64/lib >> .
> > Hi, > > Time::HiRes is not maintained by perl5-porters and bugs should be reported to the upstream CPAN author. > > You can report bugs in Time::HiRes by sending email to > > bug-Time-HiRes@rt.cpan.org > > Tony
Is this anymore relevant / reproducible? If not, I am going to soon close this ticket. (I have no access to Windows, so I cannot check things one way or another.)
On Sun Sep 25 13:20:44 2016, JHI wrote: Show quoted text
> Is this anymore relevant / reproducible? If not, I am going to soon > close this ticket. > > (I have no access to Windows, so I cannot check things one way or > another.)
No responses, closing.