>* ReduceTest.PRG > >CLEAR > >SET TALK OFF >SET DECIMALS TO 3 > >SET LIBRARY TO ( HOME( ) + "FoxTools.FLL" ) ADDITIVE > >=RunTest( "2", 1000 ) && 2^2 = 4 spaces >=RunTest( "4", 1000 ) && 2^4 = 16 spaces >=RunTest( "8", 1000 ) && 2^8 = 256 spaces >=RunTest( "16", 1000 ) && 2^16 = 65,536 spaces >=RunTest( "20", 1000 ) && 2^20 spaces > >RETURN >************************************************************* >FUNCTION RunTest > >LPARAMETERS ; > tcSpacesExponent ; > , tnPasses > >?"Spaces: 2^" + tcSpacesExponent ; > + " Passes: " + LTRIM( STR( tnPasses ) ) ; > + " Milliseconds: " + LTRIM( STR( Reduce_FoxTools( SPACE( EVALUATE( "2^" + tcSpacesExponent ) ), tnPasses ) ) ) ; > + " (REDUCE in FoxTools.FLL)" > >?"Spaces: 2^" + tcSpacesExponent ; > + " Passes: " + LTRIM( STR( tnPasses ) ) ; > + " Milliseconds: " + LTRIM( STR( Reduce_Successive( SPACE( EVALUATE( "2^" + tcSpacesExponent ) ), tnPasses ) ) ) ; > + " (Reduce_Successive)" > >?"Spaces: 2^" + tcSpacesExponent ; > + " Passes: " + LTRIM( STR( tnPasses ) ) ; > + " Milliseconds: " + LTRIM( STR( Reduce_Loop( SPACE( EVALUATE( "2^" + tcSpacesExponent ) ), tnPasses ) ) ) ; > + " (Reduce_Loop)" > >RETURN >************************************************************* >FUNCTION Reduce_FoxTools > >LPARAMETERS ; > tcString ; > , tnPasses > >LOCAL ; > lnSeconds ; > , lnIx > >lnSeconds = SECONDS( ) > >FOR lnIx = 1 TO tnPasses STEP 1 > =REDUCE( tcString ) > >ENDFOR > >RETURN ( SECONDS( ) - lnSeconds ) * 1000 > >ENDFUNC >************************************************************* >FUNCTION Reduce_Successive > >LPARAMETERS ; > tcString ; > , tnPasses > >LOCAL ; > lnSeconds ; > , lnIx > >lnSeconds = SECONDS( ) > >FOR lnIx = 1 TO tnPasses STEP 1 > * Code below handles spaces up to 2^20 long (fails on 2^20 + 1) > > tcString = STRTRAN( tcString, [ ], [ ] ) > tcString = STRTRAN( tcString, [ ], [ ] ) > tcString = STRTRAN( tcString, [ ], [ ] ) > tcString = STRTRAN( tcString, [ ], [ ] ) > tcString = STRTRAN( tcString, [ ], [ ] ) > tcString = STRTRAN( tcString, [ ], [ ] ) > tcString = STRTRAN( tcString, [ ], [ ] ) > tcString = STRTRAN( tcString, [ ], [ ] ) > >ENDFOR > >RETURN ( SECONDS( ) - lnSeconds ) * 1000 > >ENDFUNC >************************************************************* >FUNCTION Reduce_Loop > >LPARAMETERS ; > tcString ; > , tnPasses > >LOCAL ; > lnSeconds ; > , lnIx > >lnSeconds = SECONDS( ) > >FOR lnIx = 1 TO tnPasses STEP 1 > DO WHILE [ ] $ tcString > tcString = STRTRAN( tcString, [ ], [ ] ) > > ENDDO > >ENDFOR > >RETURN ( SECONDS( ) - lnSeconds ) * 1000 > >ENDFUNC >************************************************************* >>Results on my old Athlon/1000 machine:
>Spaces: 2^2 Passes: 1000 Milliseconds: 17 (REDUCE in FoxTools.FLL) >Spaces: 2^2 Passes: 1000 Milliseconds: 13 (Reduce_Successive) >Spaces: 2^2 Passes: 1000 Milliseconds: 1 (Reduce_Loop) >Spaces: 2^4 Passes: 1000 Milliseconds: 17 (REDUCE in FoxTools.FLL) >Spaces: 2^4 Passes: 1000 Milliseconds: 13 (Reduce_Successive) >Spaces: 2^4 Passes: 1000 Milliseconds: 1 (Reduce_Loop) >Spaces: 2^8 Passes: 1000 Milliseconds: 32 (REDUCE in FoxTools.FLL) >Spaces: 2^8 Passes: 1000 Milliseconds: 13 (Reduce_Successive) >Spaces: 2^8 Passes: 1000 Milliseconds: 2 (Reduce_Loop) >Spaces: 2^16 Passes: 1000 Milliseconds: 4213 (REDUCE in FoxTools.FLL) >Spaces: 2^16 Passes: 1000 Milliseconds: 15 (Reduce_Successive) >Spaces: 2^16 Passes: 1000 Milliseconds: 18 (Reduce_Loop) >Spaces: 2^20 Passes: 1000 Milliseconds: 87342 (REDUCE in FoxTools.FLL) >Spaces: 2^20 Passes: 1000 Milliseconds: 45 (Reduce_Successive) >Spaces: 2^20 Passes: 1000 Milliseconds: 295 (Reduce_Loop) >>Your technique is by far the fastest for small numbers of spaces. Mine matches yours at 65,536 spaces and is much faster with larger numbers of sequential spaces.