Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Running exact piece of code alone is 7 times faster in c
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01009816
Message ID:
01009823
Vues:
14
Zakaria,

Well the big thing is it's not the exact same code.

In the case of the method, you are pushing an argument onto the call stack, looking up the method entrypoint, and calling it. Then 1 time you access the argument, and the other 999,999 times you don't.

You'd see a somewhat similar slowdown if you used a regular function call relative to the straight code loop. But calling functions is faster by a small amount than calling methods.

Honestly this isn't a code fragment that can be really optimized anyway. Any code that would attempt to check to see if a table was used inside a tight loop should be hoisted out of the loop.

>How does it come that if I run an exact piece of code alone is ~ 7 times faster than that I run the code in a function from a class object. I don't understand why it takes so long, I would appreciate if someone could help me optimize the following:
>
>**** speedtest
>LOCAL loTest as ActSymbolen
>cFile = "C:\Actuariaat\Input\gbmgbv.dbf"
>loTest = CREATEOBJECT("ActSymbols" )
>
>time1 = SECONDS()
>
>
>*** test 1 :  using class function
>
>FOR klm = 1 TO 1000000
>
>loTest.ReadLxTables(cFile)
>ENDFOR
>? "using class function         ",SECONDS() - time1 && 15 seconds
>
>SET dataSESSION TO 2
>CLOSE DATABASES ALL
>
>
>time2 = SECONDS()
>
>*** test 2: without using class function
>FOR klm = 1 TO 1000000
>IF !USED("Gbmgbv") THEN
>	USE (cFile) IN 0
>	SELECT "gbmgbv"
>	
>ELSE
>	SELECT "gbmgbv"
>ENDIF 	
>ENDFOR
>? "without using class function" ,SECONDS() - time2 && 2 seconds
>
>
>
>
>DEFINE CLASS actSymbols as Session
>
>
>FUNCTION ReadLxTables
>LPARAMETERS cFile
>
>IF !USED("Gbmgbv") THEN
>	USE (cFile) IN 0
>	SELECT "gbmgbv"
>	
>ELSE
>	SELECT "gbmgbv"
>ENDIF 	
>
>ENDFUNC
>
>
>
>ENDDEFINE
>
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform