Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Remove excessive spaces in string
Message
 
 
À
24/07/2009 19:40:22
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01414370
Message ID:
01414413
Vues:
52
>It turns out the technique I wrote above is more "powerful" than I originally thought:
>
>- as shown above, the code (up to SPACE( 8 )) handles spaces up to 4096 long (2^12). Breaks on 4097
>- if it's extended with 2 extra lines at the top (with SPACE( 16 )) it handles spaces up to 2^20 long (breaks on 2^20 + 1)
>- having just the bottom 4 lines handles spaces up to 64 long (breaks on 65)
>
>So, we have 3 different ways to handle this:
>- FoxTools REDUCE function (Reduce_FoxTools)
>- My sequential technique (Reduce_Sequential)
>- Your looping technique (Reduce_Loop)
>
>Here's some code to test performance:
>
>* 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.
>
>Interestingly, the FoxTools REDUCE function is the big loser in all these tests.

Very interesting results, thanks for testing.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform