Results of test: with const 32.41 seconds without const 32.34 seconds Press any key to continue...
Demostration : #DEFINE REC_TEST 100000000 FUNCTION MAIN() LOCAL p, n REQUEST HB_GT_WIN p := Seconds() FOR n := 1 TO REC_TEST CallConstTest() NEXT ? " with const " + AllTrim( Str( seconds() - p ) ) + " seconds" p := Seconds() FOR n := 1 TO REC_TEST CallTest() NEXT ? " without const " + AllTrim( Str( seconds() - p ) ) + " seconds" wait RETURN NIL #pragma BEGINDUMP #include "hbapi.h" HB_FUNC( CALLCONSTTEST ) { const int posmotrim = 100; hb_retni( posmotrim ); } HB_FUNC( CALLTEST ) { int posmotrim = 100; hb_retni( posmotrim ); } #pragma ENDDUMP Przemyslaw Czerpak escribió: > On Wed, 16 Sep 2009, Enrico Maria Giordano wrote: >>> I see the previous changes of Phil, some days ago >>> i decided not port to xharbour (const) beacause it only >>> changes speed by security under some compilers. I remark >>> some compilers (BCC for example almoust at my machine) >> I can't see how the const specifier can reduce the program speed. Did you >> have a test that demostrates this? > > It may only increase the speed because it gives information to compiler > that the body of string cannot be changed by called function so it's > possible to use deeper optimizations. > Runtime protection (if any) is done using readonly memory segments and > it also can only increase the speed because CPU can use cache more > efficiently when it knows that some memory pages cannot be modified, > i.e. it does not have to update or sync them on write. > There is no technical reasons to reduce the speed by using 'const' modifier > everywhere it's possible but they are situations when missing 'const' > reduces the speed. > So it improve the speed and also gives additional compile time > protection which nicely helps to locate and fix some type of bugs. > > best regards, > Przemek > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry® Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9-12, 2009. Register now! > http://p.sf.net/sfu/devconf > _______________________________________________ > xHarbour-developers mailing list > xHarbour-developers@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/xharbour-developers > > __________ Información de ESET NOD32 Antivirus, versión de la base de firmas > de virus 4429 (20090916) __________ > > ESET NOD32 Antivirus ha comprobado este mensaje. > > http://www.eset.com > > > > __________ Información de ESET NOD32 Antivirus, versión de la base de firmas de virus 4429 (20090916) __________ ESET NOD32 Antivirus ha comprobado este mensaje. http://www.eset.com ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ xHarbour-developers mailing list xHarbour-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xharbour-developers