Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Evaluate() on a built field name
Message
De
18/01/2006 02:41:03
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Database:
Visual FoxPro
Divers
Thread ID:
01087596
Message ID:
01087859
Vues:
18
>Fabio,
>
>Yes, tests are necessary. And if you'd taken the time to test before posting you'd have found out that a dynamic STORE command is a little (5%) to significantly faster (80%) than AddProperty().
>
>
>create cursor x1 ( comment01 c(100), ;
>   comment02 c(100), ;
>   comment03 c(100), ;
>   comment04 c(100), ;
>   comment05 c(100) )
>
>scatter name loData blank
>
>insert into x1 values ( "", replicate( 'x', 30 ), replicate( 'y', 60 ), ;
>   replicate( 'z', 90 ), replicate( 'a', 100 ) )
>
>? "Test a large trim"
>
>ltStart = seconds()
>
>for i = 1 to 100000
>   for j = 1 to 5
>      store alltrim( x1.comment01 ) to ("loData.comment" + padl( m.j, 2, '0' ) )
>   endfor
>endfor
>
>ltStart = seconds() - ltStart
>? "store:", ltStart
>
>ltStart = seconds()
>
>for i = 1 to 100000
>   for j = 1 to 5
>      addproperty( loData, "comment" + padl( m.j, 2, '0' ), alltrim( x1.comment01 ) )
>   endfor
>endfor
>
>ltStart = seconds() - ltStart
>? "AddProperty:", ltStart
>
>
>? "Test a short trim"
>
>ltStart = seconds()
>
>for i = 1 to 100000
>   for j = 1 to 5
>      store alltrim( x1.comment04 ) to ("loData.comment" + padl( m.j, 2, '0' ) )
>   endfor
>endfor
>
>ltStart = seconds() - ltStart
>? "store:", ltStart
>
>ltStart = seconds()
>
>for i = 1 to 100000
>   for j = 1 to 5
>      addproperty( loData, "comment" + padl( m.j, 2, '0' ), alltrim( x1.comment04 ) )
>   endfor
>endfor
>
>ltStart = seconds() - ltStart
>? "AddProperty:", ltStart
>
>? "Test just raw store vs. addproperty()"
>
>ltStart = seconds()
>
>for i = 1 to 100000
>   for j = 1 to 5
>      store alltrim( x1.comment01 ) to loData.comment01
>   endfor
>endfor
>
>ltStart = seconds() - ltStart
>? "store:", ltStart
>
>ltStart = seconds()
>
>for i = 1 to 100000
>   for j = 1 to 5
>      addproperty( loData, "comment01", alltrim( x1.comment01 ) )
>   endfor
>endfor
>
>ltStart = seconds() - ltStart
>? "AddProperty:", ltStart
>
>? "Test all comments to properties"
>
>ltStart = seconds()
>
>for i = 1 to 100000
>   for j = 1 to 5
>      lcName = padl( m.j, 2, '0' )
>      store alltrim( evaluate( "x1.comment" + lcName ) ) to ("loData.comment" + lcName )
>   endfor
>endfor
>
>ltStart = seconds() - ltStart
>? "store:", ltStart
>
>ltStart = seconds()
>
>for i = 1 to 100000
>   for j = 1 to 5
>      lcName = padl( m.j, 2, '0' )
>      addproperty( loData, "comment" + lcName, alltrim( evaluate( "x1.comment" + lcName ) ) )
>   endfor
>endfor
>
>ltStart = seconds() - ltStart
>? "AddProperty:", ltStart
>
>? "Test just raw store vs. addproperty() for all comments"
>
>ltStart = seconds()
>
>for i = 1 to 100000
>   store alltrim( x1.comment01 ) to loData.comment01
>   store alltrim( x1.comment02 ) to loData.comment02
>   store alltrim( x1.comment03 ) to loData.comment03
>   store alltrim( x1.comment04 ) to loData.comment04
>   store alltrim( x1.comment05 ) to loData.comment05
>endfor
>
>ltStart = seconds() - ltStart
>? "store:", ltStart
>
>ltStart = seconds()
>
>for i = 1 to 100000
>   addproperty( loData, "comment01", alltrim( x1.comment01 ) )
>   addproperty( loData, "comment02", alltrim( x1.comment02 ) )
>   addproperty( loData, "comment03", alltrim( x1.comment03 ) )
>   addproperty( loData, "comment04", alltrim( x1.comment04 ) )
>   addproperty( loData, "comment05", alltrim( x1.comment05 ) )
>endfor
>
>ltStart = seconds() - ltStart
>? "AddProperty:", ltStart
>
>

Of course,
the presupposition is that one knows VFP,
and knows how to correctly write a program; this is not your case.

Raw is out of the issue, then leave it out please.

We go:
CLEAR

create cursor x1 ( comment01 c(100), ;
   comment02 c(100), ;
   comment03 c(100), ;
   comment04 c(100), ;
   comment05 c(100) )

scatter name loData blank

insert into x1 values ( "", replicate( 'x', 30 ), replicate( 'y', 60 ), ;
   replicate( 'z', 90 ), replicate( 'a', 100 ) )

? "David's wrong VFP code: wthou m. VFP loop into the x1 fields"
DavidBadCode()

SELECT 0
?
? "workaround for wrong code: unselect a active alias"
DavidBadCode()

SELECT x1
?
? "correct test"

CorrectCode()

PROCEDURE DavidBadCode

? "Test a large trim"

ltStart = seconds()

for i = 1 to 100000
   for j = 1 to 5
      store alltrim( x1.comment01 ) to ("loData.comment" + padl( m.j, 2, '0' ) )
   endfor
endfor

ltStart = seconds() - ltStart
? "store:", ltStart

ltStart = seconds()

for i = 1 to 100000
   for j = 1 to 5
      addproperty( loData, "comment" + padl( m.j, 2, '0' ), alltrim( x1.comment01 ) )
   endfor
endfor

ltStart = seconds() - ltStart
? "AddProperty:", ltStart


? "Test a short trim"

ltStart = seconds()

for i = 1 to 100000
   for j = 1 to 5
      store alltrim( x1.comment04 ) to ("loData.comment" + padl( m.j, 2, '0' ) )
   endfor
endfor

ltStart = seconds() - ltStart
? "store:", ltStart

ltStart = seconds()

for i = 1 to 100000
   for j = 1 to 5
      addproperty( loData, "comment" + padl( m.j, 2, '0' ), alltrim( x1.comment04 ) )
   endfor
endfor

ltStart = seconds() - ltStart
? "AddProperty:", ltStart

? "Test all comments to properties"

ltStart = seconds()

for i = 1 to 100000
   for j = 1 to 5
      lcName = padl( m.j, 2, '0' )
      store alltrim( evaluate( "x1.comment" + lcName ) ) to ("loData.comment" + lcName )
   endfor
endfor

ltStart = seconds() - ltStart
? "store:", ltStart

ltStart = seconds()

for i = 1 to 100000
   for j = 1 to 5
      lcName = padl( m.j, 2, '0' )
      addproperty( loData, "comment" + lcName, alltrim( evaluate( "x1.comment" + lcName ) ) )
   endfor
endfor

ltStart = seconds() - ltStart
? "AddProperty:", ltStart

ENDPROC

****************************************

PROCEDURE CorrectCode
? "Test a large trim"

ltStart = seconds()

for i = 1 to 100000
   for j = 1 to 5
      store alltrim( x1.comment01 ) to ("loData.comment" + padl( m.j, 2, '0' ) )
   endfor
endfor

ltStart = seconds() - ltStart
? "store:", ltStart

ltStart = seconds()

for i = 1 to 100000
   for j = 1 to 5
      addproperty( m.loData, "comment" + padl( m.j, 2, '0' ), alltrim( x1.comment01 ) )
   endfor
endfor

ltStart = seconds() - ltStart
? "AddProperty:", ltStart


? "Test a short trim"

ltStart = seconds()

for i = 1 to 100000
   for j = 1 to 5
      store alltrim( x1.comment04 ) to ("loData.comment" + padl( m.j, 2, '0' ) )
   endfor
endfor

ltStart = seconds() - ltStart
? "store:", ltStart

ltStart = seconds()

for i = 1 to 100000
   for j = 1 to 5
      addproperty( m.loData, "comment" + padl( m.j, 2, '0' ), alltrim( x1.comment04 ) )
   endfor
endfor

ltStart = seconds() - ltStart
? "AddProperty:", ltStart

? "Test all comments to properties"

ltStart = seconds()

for i = 1 to 100000
   for j = 1 to 5
      lcName = padl( m.j, 2, '0' )
      store alltrim( evaluate( "x1.comment" + m.lcName ) ) to ("loData.comment" + m.lcName )
   endfor
endfor

ltStart = seconds() - ltStart
? "store:", ltStart

ltStart = seconds()

for i = 1 to 100000
   for j = 1 to 5
      lcName = padl( m.j, 2, '0' )
      addproperty( m.loData, "comment" + m.lcName, alltrim( evaluate( "x1.comment" + m.lcName ) ) )
   endfor
endfor

ltStart = seconds() - ltStart
? "AddProperty:", ltStart

ENDPROC
>>not tests are necessary, because if the VFP's C++ implementation is correct
>>it is obvious that ADDPROP is more express of TO (...),
>>as ADDPROP() it is a more specific command. For this reason it is also clearer.
>>
>>to read a variable property the correct way is : GETPEM
>>
>>to write a variable defined property the correct way is : ADDPROP(),
>>of course, except if you want a error if the property don't exist.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform