diff --git a/harbour/ChangeLog b/harbour/ChangeLog index d298e2fd84..0b30461e10 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,19 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-09-15 23:08 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + + harbour/tests/memtst.prg + + added some simple tests for memory manager + + * harbour/tests/speedtst.prg + * reduced the size of allocated block size to not test C-RTL + memory manager but HVM speed + + * harbour/include/hbthread.h + * added for x86@32 PTHREADS builds HB_ATOM_GET() and HB_ATOM_SET() + so they can be used together with HB_ATOM_INC()/HB_ATOM_DEC() + also for x86@64 but with reduced to 32bit reference counter. + 2008-09-15 21:05 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * make_b32.mak * contrib/mtpl_b32.mak diff --git a/harbour/include/hbthread.h b/harbour/include/hbthread.h index 0a51f1c1ce..9950a52a02 100644 --- a/harbour/include/hbthread.h +++ b/harbour/include/hbthread.h @@ -128,6 +128,8 @@ HB_EXTERN_BEGIN # define HB_ATOM_INC( p ) ( hb_atomic_inc32( ( volatile int * ) (p) ) ) # define HB_ATOM_DEC( p ) ( hb_atomic_dec32( ( volatile int * ) (p) ) ) +# define HB_ATOM_GET( p ) (*(int volatile *)(p)) +# define HB_ATOM_SET( p, n ) do { (*(int volatile *)(p)) = (n); } while(0) # endif diff --git a/harbour/tests/memtst.prg b/harbour/tests/memtst.prg new file mode 100644 index 0000000000..9ed51c5ac5 --- /dev/null +++ b/harbour/tests/memtst.prg @@ -0,0 +1,100 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * a small memory mangaer test code + */ + +#define N_LOOPS 100000 + +#ifdef __HARBOUR__ + #include "hbmemory.ch" +#endif + +proc main() +local nCPUSec, nRealSec, i, a + +#ifdef __HARBOUR__ +if MEMORY( HB_MEM_USEDMAX ) != 0 + ? + ? "Warning !!! Memory statistic enabled." +endif +#endif +? +? date(), time(), VERSION()+build_mode()+", "+OS() + +? +? "testing single large memory blocks allocation and freeing..." +nRealSec := seconds() +nCPUSec := secondsCPU() +for i := 1 to N_LOOPS + a := space( 50000 ) +next +a := NIL +nCPUSec := secondsCPU() - nCPUSec +nRealSec := seconds() - nRealSec +? " CPU time:", nCPUSec, "sec." +? "real time:", nRealSec, "sec." + +? +? "testing many large memory blocks allocation and freeing..." +nRealSec := seconds() +nCPUSec := secondsCPU() +a := array(100) +for i := 1 to N_LOOPS + a[ i % 100 + 1 ] := space( 50000 ) + if i % 200 == 0 + afill(a,"") + endif +next +a := NIL +nCPUSec := secondsCPU() - nCPUSec +nRealSec := seconds() - nRealSec +? " CPU time:", nCPUSec, "sec." +? "real time:", nRealSec, "sec." + +? +? "testing large memory block reallocation with intermediate allocations..." +? "Warning!!! some compilers may badly fail here" +wait + +nRealSec := seconds() +nCPUSec := secondsCPU() +a := {} +for i := 1 to N_LOOPS + aadd( a, {} ) + if i%1000 == 0 + ?? i + endif +next +nCPUSec := secondsCPU() - nCPUSec +nRealSec := seconds() - nRealSec +? " CPU time:", nCPUSec, "sec." +? "real time:", nRealSec, "sec." +wait + +return + + +function build_mode() +#ifdef __CLIP__ + return " (MT)" +#else + #ifdef __XHARBOUR__ + return iif( HB_MULTITHREAD(), " (MT)", "" ) + ; + iif( MEMORY( HB_MEM_USEDMAX ) != 0, " (FMSTAT)", "" ) + #else + #ifdef __HARBOUR__ + return iif( HB_MTVM(), " (MT)", "" ) + ; + iif( MEMORY( HB_MEM_USEDMAX ) != 0, " (FMSTAT)", "" ) + #else + #ifdef __XPP__ + return " (MT)" + #else + return "" + #endif + #endif + #endif +#endif diff --git a/harbour/tests/speedtst.prg b/harbour/tests/speedtst.prg index ad642fbf0c..3c390180b8 100644 --- a/harbour/tests/speedtst.prg +++ b/harbour/tests/speedtst.prg @@ -29,6 +29,7 @@ #xtranslate seconds() => fs_seconds() #endif #ifdef __HARBOUR__ + #include "hbmemory.ch" #define ASSOC_ARRAY { => } #undef REAL_TIME #endif @@ -84,8 +85,18 @@ for i:=1 to len(a) a3[i]:=stuff(dtos(date()),7,0,".") next +#ifdef __HARBOUR__ +if MEMORY( HB_MEM_USEDMAX ) != 0 + ? + ? "Warning !!! Memory statistic enabled." +endif +#endif ? -? date(), time(), VERSION()+mt_mode()+", "+OS() +? "Startup loop to increase CPU clock..." +t:=seconds()+5; while t > seconds(); enddo + +? +? date(), time(), VERSION()+build_mode()+", "+OS() ? "ARR_LEN =", ARR_LEN ? "N_LOOPS =", N_LOOPS @@ -489,20 +500,22 @@ function f3(a,b,c,d,e,f,g,h,i) return nil function f4() -return space(40000) +return space(4000) function f5() return space(5) -function mt_mode() +function build_mode() #ifdef __CLIP__ return " (MT)" #else #ifdef __XHARBOUR__ - return iif( HB_MULTITHREAD(), " (MT)", "" ) + return iif( HB_MULTITHREAD(), " (MT)", "" ) + ; + iif( MEMORY( HB_MEM_USEDMAX ) != 0, " (FMSTAT)", "" ) #else #ifdef __HARBOUR__ - return iif( HB_MTVM(), " (MT)", "" ) + return iif( HB_MTVM(), " (MT)", "" ) + ; + iif( MEMORY( HB_MEM_USEDMAX ) != 0, " (FMSTAT)", "" ) #else #ifdef __XPP__ return " (MT)"