diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3e5dd4c93f..df2b6bf59e 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,24 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-12-25 11:14 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) + * include/hbextern.ch + * source/rtl/seconds.c + + implemented hb_milliseconds(). This function returns time value + from some moment in the past (not midnigth!). It does not start + to cound from zero in midnight, thus, can be safetly used to + measure time intervals. + + tests/ticktime.c + + Added nice test for hb_milliseconds(). + Results on WinXP: + Ticks per second: 63.595 + Min/avg/max interval (ms): 15.000 / 15.724 / 47.000 + Loops per tick: 13035.09 + Results on openSUSE on VirtualBox on WinXP: + Ticks per second: 384306.138 + Min/avg/max interval (ms): 0.001 / 0.003 / 11.112 + Loops per tick: 1.04 + 2008-12-25 08:20 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) * contrib/rddsql/sqlpg/make_b32.bat * contrib/rddsql/sqlpg/make_vc.bat diff --git a/harbour/include/hbextern.ch b/harbour/include/hbextern.ch index ef7350b8b8..5c9f285b7f 100644 --- a/harbour/include/hbextern.ch +++ b/harbour/include/hbextern.ch @@ -1176,6 +1176,7 @@ EXTERNAL HB_STRSHRINK EXTERNAL HB_MEMOREAD EXTERNAL HB_MEMOWRIT EXTERNAL HB_NTOS +EXTERNAL HB_MILLISECONDS EXTERNAL HB_HASH EXTERNAL HB_HHASKEY diff --git a/harbour/source/rtl/seconds.c b/harbour/source/rtl/seconds.c index e82a63c700..310ff73618 100644 --- a/harbour/source/rtl/seconds.c +++ b/harbour/source/rtl/seconds.c @@ -228,11 +228,19 @@ double hb_dateSeconds( void ) #endif } + HB_FUNC( SECONDS ) { hb_retnd( hb_dateSeconds() ); } + +HB_FUNC( HB_MILLISECONDS ) +{ + hb_retnint( ( HB_LONG ) hb_dateMilliSeconds() ); +} + + HB_FUNC( HB_CLOCKS2SECS ) { #ifdef CLOCKS_PER_SEC diff --git a/harbour/tests/ticktime.prg b/harbour/tests/ticktime.prg new file mode 100644 index 0000000000..86179a4ac5 --- /dev/null +++ b/harbour/tests/ticktime.prg @@ -0,0 +1,25 @@ +/* +* $Id$ +*/ + +PROC main() +LOCAL nTime0, nTime, nTimeLast, nMin := 9999, nMax := -9999, nTick := 0, nLoop := 0 + + ? "Wait for 10 seconds..." + nTimeLast := nTime0 := HB_MILLISECONDS() + DO WHILE ( nTime := HB_MILLISECONDS() ) - nTime0 < 10000 + IF nTimeLast != nTime + nTick++ + nMin := MIN(nMin, nTime - nTimeLast) + nMax := MAX(nMax, nTime - nTimeLast) + nTimeLast := nTime + ENDIF + nLoop++ + ENDDO + nTime := nTimeLast - nTime0 + ? "Ticks per second:", LTRIM(STR(nTick * 1000/ nTime, 12, 3)) + ? "Min/avg/max interval (ms):", LTRIM(STR(nMin, 9, 3)), "/", ; + LTRIM(STR(nTime / nTick, 9, 3)), "/", ; + LTRIM(STR(nMax, 9, 3)) + ? "Loops per tick:", nLoop / nTick +RETURN