We have hb_secondsCPU() in core, maybe code below could be 
incorporated into it.

Brgds,
Viktor

On 2010 Jan 7, at 16:56, Mindaugas Kavaliauskas wrote:

> Hi,
> 
> Mindaugas Kavaliauskas wrote:
>>> BTW how expensive (time consuming) is WINSOCK initialization in MS-Windows?
>>      HB_ULONG ulTime = hb_dateMilliSeconds();
>>      hb_socketInit();
>>      HB_TRACE( HB_TR_ALWAYS, ("hb_socketInit() time=%d", 
>> hb_dateMilliSeconds() - ulTime) );
>> prints:
>> netiocli.c:470: HB_TR_ALWAYS hb_socketInit() time=0
>> Do you have any other test code for it?
> 
> Some time ago I was testing Python, Ruby, Java, etc speed. I was surprised 
> about how Python's clock() function. It returns a lot of decimals on Windows. 
> I've looked into the source and found a useful Win32 API function 
> QueryPerformanceCounter for implementation of a high precision timer in 
> Windows.
> 
> Here is the simplest version:
> #include "windows.h"
> static LARGE_INTEGER iStart;
> static LARGE_INTEGER iFreq = {0};
> double hpclock( void )
> {
>  LARGE_INTEGER iTime;
>  if( iFreq.QuadPart == 0 )
>  {
>    QueryPerformanceCounter( &iStart );
>    QueryPerformanceFrequency( &iFreq );
>  }
>  QueryPerformanceCounter( &iTime );
>  return ( double )( iTime.QuadPart - iStart.QuadPart ) / ( double ) 
> iFreq.QuadPart;
> }
> 
> The modified s_netio_init() code:
>      double dTime = hpclock();
>      hb_socketInit();
>      HB_TRACE( HB_TR_ALWAYS, ("hb_socketInit() time=%g", hpclock() - dTime) );
>      dTime = hpclock();
>      Sleep(1000);
>      HB_TRACE( HB_TR_ALWAYS, ("1 second =%g", hpclock() - dTime) );
>      HB_TRACE( HB_TR_ALWAYS, ("hpclock() overhead=%g", hpclock() - hpclock()) 
> );
> 
> prints:
> 
> C:\harbour\contrib\hbnetio\tests>rpctest.exe
> netiocli.c:489: HB_TR_ALWAYS hb_socketInit() time=0.00185554
> netiocli.c:492: HB_TR_ALWAYS 1 second =1.00001
> netiocli.c:493: HB_TR_ALWAYS hpclock() overhead=-1.67619e-06
> 
> .T.
> C:\harbour\contrib\hbnetio\tests>rpctest.exe
> netiocli.c:489: HB_TR_ALWAYS hb_socketInit() time=0.00119596
> netiocli.c:492: HB_TR_ALWAYS 1 second =0.999618
> netiocli.c:493: HB_TR_ALWAYS hpclock() overhead=-1.67619e-06
> 
> .T.
> C:\harbour\contrib\hbnetio\tests>rpctest.exe
> netiocli.c:489: HB_TR_ALWAYS hb_socketInit() time=0.00146946
> netiocli.c:492: HB_TR_ALWAYS 1 second =0.999511
> netiocli.c:493: HB_TR_ALWAYS hpclock() overhead=-1.39683e-06
> 
> .T.
> C:\harbour\contrib\hbnetio\tests>rpctest.exe
> netiocli.c:489: HB_TR_ALWAYS hb_socketInit() time=0.00144739
> netiocli.c:492: HB_TR_ALWAYS 1 second =0.999809
> netiocli.c:493: HB_TR_ALWAYS hpclock() overhead=-1.67619e-06
> 
> .T.
> C:\harbour\contrib\hbnetio\tests>rpctest.exe
> netiocli.c:489: HB_TR_ALWAYS hb_socketInit() time=0.00116998
> netiocli.c:492: HB_TR_ALWAYS 1 second =0.999526
> netiocli.c:493: HB_TR_ALWAYS hpclock() overhead=-1.67619e-06
> 
> .T.
> C:\harbour\contrib\hbnetio\tests>rpctest.exe
> netiocli.c:489: HB_TR_ALWAYS hb_socketInit() time=0.00183431
> netiocli.c:492: HB_TR_ALWAYS 1 second =0.99934
> netiocli.c:493: HB_TR_ALWAYS hpclock() overhead=-1.39683e-06
> 
> .T.
> C:\harbour\contrib\hbnetio\tests>rpctest.exe
> netiocli.c:489: HB_TR_ALWAYS hb_socketInit() time=0.00191924
> netiocli.c:492: HB_TR_ALWAYS 1 second =0.99944
> netiocli.c:493: HB_TR_ALWAYS hpclock() overhead=-1.95556e-06
> 
> .T.
> C:\harbour\contrib\hbnetio\tests>rpctest.exe
> netiocli.c:489: HB_TR_ALWAYS hb_socketInit() time=0.00148734
> netiocli.c:492: HB_TR_ALWAYS 1 second =0.999669
> netiocli.c:493: HB_TR_ALWAYS hpclock() overhead=-1.67619e-06
> 
> .T.
> 
> We already have two time functions that return seconds from midnight and 
> milliseconds (absolute UTC), but sometimes it is useful to have a higher 
> precision time function and a function that "ignores" adjustment of computer 
> time. The proposed function has these properties, but I do not know if such 
> implementation is possible in another platforms. I guess this clock uses CPU 
> clock counter, so, I do not know how it works in real multi-CPU environment.
> 
> 
> Regards,
> Mindaugas
> _______________________________________________
> Harbour mailing list (attachment size limit: 40KB)
> Harbour@harbour-project.org
> http://lists.harbour-project.org/mailman/listinfo/harbour

_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to